Refactor/unify access to static attributes by ilevkivskyi · Pull Request #19254 · python/mypy

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.