-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Improve handling of attribute access on class objects #14988
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -325,7 +325,10 @@ class X(NamedTuple): | |||||
reveal_type(X._fields) # N: Revealed type is "Tuple[builtins.str, builtins.str]" | ||||||
reveal_type(X._field_types) # N: Revealed type is "builtins.dict[builtins.str, Any]" | ||||||
reveal_type(X._field_defaults) # N: Revealed type is "builtins.dict[builtins.str, Any]" | ||||||
reveal_type(X.__annotations__) # N: Revealed type is "builtins.dict[builtins.str, Any]" | ||||||
|
||||||
# In typeshed's stub for builtins.pyi, __annotations__ is `dict[str, Any]`, | ||||||
# but it's inferred as `Mapping[str, object]` here due to the fixture we're using | ||||||
reveal_type(X.__annotations__) # N: Revealed type is "typing.Mapping[builtins.str, builtins.object]" | ||||||
|
||||||
[builtins fixtures/dict.pyi] | ||||||
Comment on lines
+329
to
333
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test needed to be altered slightly, as with this change, mypy starts inferring the correct type of mypy/test-data/unit/fixtures/dict.pyi Lines 16 to 17 in 89469ac
|
||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4521,6 +4521,39 @@ def f(TA: Type[A]): | |
reveal_type(TA) # N: Revealed type is "Type[__main__.A]" | ||
reveal_type(TA.x) # N: Revealed type is "builtins.int" | ||
|
||
[case testMetaclassConflictingInstanceVars] | ||
from typing import ClassVar | ||
|
||
class Meta(type): | ||
foo: int | ||
bar: int | ||
eggs: ClassVar[int] = 42 | ||
spam: ClassVar[int] = 42 | ||
|
||
class Foo(metaclass=Meta): | ||
foo: str | ||
bar: ClassVar[str] = 'bar' | ||
eggs: str | ||
spam: ClassVar[str] = 'spam' | ||
Comment on lines
+4535
to
+4537
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could argue that |
||
|
||
reveal_type(Foo.foo) # N: Revealed type is "builtins.int" | ||
reveal_type(Foo.bar) # N: Revealed type is "builtins.str" | ||
reveal_type(Foo.eggs) # N: Revealed type is "builtins.int" | ||
reveal_type(Foo.spam) # N: Revealed type is "builtins.str" | ||
|
||
class MetaSub(Meta): ... | ||
|
||
class Bar(metaclass=MetaSub): | ||
foo: str | ||
bar: ClassVar[str] = 'bar' | ||
eggs: str | ||
spam: ClassVar[str] = 'spam' | ||
|
||
reveal_type(Bar.foo) # N: Revealed type is "builtins.int" | ||
reveal_type(Bar.bar) # N: Revealed type is "builtins.str" | ||
reveal_type(Bar.eggs) # N: Revealed type is "builtins.int" | ||
reveal_type(Bar.spam) # N: Revealed type is "builtins.str" | ||
|
||
[case testSubclassMetaclass] | ||
class M1(type): | ||
x = 0 | ||
|
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.
and not hook
was required here, or this test started to fail:mypy/test-data/unit/check-custom-plugin.test
Lines 974 to 990 in 89469ac