-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Cleanup generic class variable access #19292
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
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
Diff from mypy_primer, showing the effect of this PR on open source code: ibis (https://github.com/ibis-project/ibis)
- ibis/common/bases.py:110: error: Unsupported target for indexed assignment ("Mapping[Any, Any]") [index]
+ ibis/common/bases.py:110: error: Unsupported target for indexed assignment ("Mapping[Any, Self]") [index]
hydpy (https://github.com/hydpy-dev/hydpy)
+ hydpy/core/variabletools.py:2448: error: Unused "type: ignore" comment [unused-ignore]
artigraph (https://github.com/artigraph/artigraph)
- src/arti/internal/mappings.py:100: error: ClassVar cannot contain type variables [misc]
+ src/arti/storage/__init__.py:74: error: Unused "type: ignore" comment [unused-ignore]
comtypes (https://github.com/enthought/comtypes)
+ comtypes/hints.pyi:56: error: Unused "type: ignore" comment [unused-ignore]
pwndbg (https://github.com/pwndbg/pwndbg)
- pwndbg/aglib/heap/structs.py:175: error: Access to generic instance variables via class is ambiguous [misc]
- pwndbg/aglib/heap/structs.py:206: error: Access to generic instance variables via class is ambiguous [misc]
|
|
x: Tuple[Unpack[Ts]] | ||
|
||
reveal_type(C.x) # E: Access to generic instance variables via class is ambiguous \ | ||
# N: Revealed type is "builtins.tuple[Any, ...]" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test also defining a subclass and then accessing the attribute via the subclass, and an instance of the subclass?
[case testSelfTypeClassMethodNotSilentlyErased] | ||
from typing import ClassVar, Self, Optional | ||
|
||
class X: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test subclassing and accessing _inst
outside the class body?
x: T | ||
y: ClassVar[T] | ||
|
||
class C(B[T]): ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to also test attribute access in cases like class D(B[int]): ...
. Should D.y
have type int
then?
Fixes #5144
Fixes #15223
This is related to the work on #7724
Now that all attribute access goes through
checkmember.py
there is not much benefit in giving an error at the definition site, especially that it prohibits some valid (and common) use cases, see comments in #5144. While looking at this I discovered a bunch of defects in the implementation, that I also fix (I am keeping unsafe self-type related logic as is):Any
even in allowed use casesTypeVarTuple
andParamSpec
were not handled as equal to regular type variables (I guess because of old problems with erasing them)