Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

sterliakov
Copy link
Collaborator

@sterliakov sterliakov commented Jun 26, 2025

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:

def foo() -> None:
    __slots__ = 1

@sterliakov sterliakov changed the title Infer empty list without annotation in __slots__ Infer empty list without annotation for __slots__ Jun 26, 2025
@sterliakov sterliakov changed the title Infer empty list without annotation for __slots__ Infer empty list without annotation for __slots__ and module __all__ Jun 27, 2025

This comment has been minimized.

@sterliakov sterliakov requested a review from sobolevn June 27, 2025 15:35

This comment has been minimized.

This comment has been minimized.

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Thank you!

Copy link
Contributor

github-actions bot commented Jul 7, 2025

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

Sign up for free to 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
2 participants