KEMBAR78
Infer empty list without annotation for `__slots__` and module `__all__` by sterliakov · Pull Request #19348 · python/mypy · GitHub
Skip to content

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
@github-actions

This comment has been minimized.

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

This comment has been minimized.

@github-actions

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!

@github-actions
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. ✅

@JukkaL JukkaL merged commit 1091321 into python:master Jul 9, 2025
19 checks passed
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

3 participants