Skip to content

Refactor/unify access to static attributes #19254

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

Merged
merged 3 commits into from
Jun 9, 2025

Conversation

ilevkivskyi
Copy link
Member

@ilevkivskyi ilevkivskyi commented Jun 8, 2025

Fixes #3832
Fixes #5723
Fixes #17174
Improves #7217

This is a sixth "major" PR toward #7724. Previously access to "static" attributes (like type aliases, class objects) was duplicated in four places:

  • In analyze_ref_expr()
  • In determine_type_of_member() (for modules as subtypes of protocols)
  • In instance attribute access logic
  • In class attribute logic

Most of these were somewhat incomplete and/or inconsistent, this PR unifies all four (there is still tiny duplication because I decided to limit the number of deferrals, i.e. preserve the existing logic in this respect). Some notable things that are not pure refactoring:

  • Previously we disabled access to type variables as class attributes. This was inconsistent with plain references and instance attributes that just return Instance("typing.TypeVar").
  • Instance access plugins were only applied on TypeInfos and TypeAliases, now they are applied always.
  • Previously arguments kinds were sometimes not correct for TypedDict class objects with non-required keys.
  • I tweaked TypeOfAny in couple places to be more logical.

@ilevkivskyi ilevkivskyi requested a review from JukkaL June 8, 2025 20:05

This comment has been minimized.

Copy link
Contributor

github-actions bot commented Jun 8, 2025

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

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Nice to see more duplicate code paths getting merged!

@ilevkivskyi ilevkivskyi merged commit 929377a into python:master Jun 9, 2025
19 checks passed
@ilevkivskyi ilevkivskyi deleted the unify-static-attrs branch June 9, 2025 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants