Skip to content

implicit-any-empty-container raised on chained assignment #3969

Description

@pkerichang

Describe the Bug

pyrefly is able to infer the empty container type in the following code:

key: str = "foo"
table: dict[str, dict[str, int]] = {}
foo = table.get(key, None)
if foo is None:
    foo = {}
    table[key] = foo

however, if chained assignment is used to save one line, then pyrefly now reports an implicit-any-empty-container error:

key: str = "foo"
table: dict[str, dict[str, int]] = {}
foo = table.get(key, None)
if foo is None:
    foo = table[key] = {}  # pyrefly reports error here

The chain assignment order does not matter, this also fails:

key: str = "foo"
table: dict[str, dict[str, int]] = {}
foo = table.get(key, None)
if foo is None:
    table[key] = foo = {}  # pyrefly reports error here

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions