Skip to content

Narrowing gets lost in loops #820

@ndmitchell

Description

@ndmitchell

Describe the Bug

from typing import *

class Foo:
    autogrids: None | dict[str, Any]

    def f(self, xs: list[int]):
        self.autogrids = {}
        for a in []:
            self.autogrids["test"] = True # E: ERROR 9:13-35: Cannot set item in `None`

We should remember that autogrids is always going to be a dict at this point.

Sandbox Link

https://pyrefly.org/sandbox/?code=GYJw9gtgBALgngBwJYDsDmUkQWEMoBUAUEQMYA2AhgM7VQBiYYAXEVO1JQK4xhohIAJtWZQAcmBQBTKAB8ogpKRgBtajBAAaKAEEUcALokOCqcCjAAFNSnlg2gB4io5JOpWoYBgJSsTJmzsAOm5efiE6AF4oAG8AXzZ-dmBcTkwUKBUDPyT-QOAQnj4BYRUAIhgpdTKDKGiAFRAuKSIgA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions