Skip to content

Infer empty list without annotation for __slots__ and module __all__ - #19348

Merged
JukkaL merged 7 commits into
python:masterfrom
sterliakov:feature/gh-10870-infer-slots-empty-list
Jul 9, 2025
Merged

Infer empty list without annotation for __slots__ and module __all__#19348
JukkaL merged 7 commits into
python:masterfrom
sterliakov:feature/gh-10870-infer-slots-empty-list

Conversation

@sterliakov

@sterliakovsterliakov commented Jun 26, 2025

Copy link
Copy Markdown
Collaborator

Fixes#10870, fixes#10103.

This adds a fake Iterable[str] context when checking the following:

  • __all__ = [] at top level
  • __slots__ = [] at class level (also works for sets but not for dicts)

Additionally, this fixes a bug with __slots__ being mistakenly checked in other contexts (at top level or in function bodies), so e.g. the following is now accepted:

deffoo() ->None:
__slots__=1

@sterliakovsterliakov changed the title Infer empty list without annotation in __slots__Infer empty list without annotation for __slots__Jun 26, 2025
@sterliakovsterliakov changed the title Infer empty list without annotation for __slots__Infer empty list without annotation for __slots__ and module __all__Jun 27, 2025
@github-actions

This comment has been minimized.

@sterliakov
sterliakov requested a review from sobolevnJune 27, 2025 15:35
Comment threadmypy/checker.py
Comment threadtest-data/unit/check-slots.test
Comment threadtest-data/unit/check-slots.test
@github-actions

This comment has been minimized.

Comment threadtest-data/unit/check-slots.test
@github-actions

This comment has been minimized.

@sobolevnsobolevn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@JukkaL
JukkaL merged commit 1091321 into python:masterJul 9, 2025
19 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mypy complains when [] is used for __slots__ definition Mypy complains about empty __all__ being untyped

3 participants

@sterliakov@sobolevn@JukkaL