-
-
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
mypyc: Cls.__dict__
is mappingproxy
, not dict
#14056
Comments
Currently the stub for def vars(__object: Any = ...) -> dict[str, Any]: ... Maybe it should be this: def vars(__object: Any = ...) -> Mapping[str, Any]: ... Or this: @overload
def vars(__object: type) -> types.MappingProxyType[str, Any]: ...
@overload
def vars(__object: Any = ...) -> dict[str, Any]: ... However, that doesn't explain why mypyc seems to think that |
python/typeshed#9146 has just been merged, which improves the signature for |
@AlexWaygood I didn't find docs how to install latest typeshed and my try to install it directly into venv from git failed. Is there any way to update typeshed to test new behavior? |
In general you can get mypy to use the latest typeshed using the Unfortunately if I do It looks like the issue with |
It's a mypy bug rather than a mypyc bug, and it stems from a more general bug where mypy misunderstands how attribute access on class objects should be understood when metaclasses are involved. Here's a minimal repro: class Meta(type):
bar: str
class Foo(metaclass=Meta):
bar: int
reveal_type(Foo().bar) # Revealed type is int (correct!)
reveal_type(Foo.bar) # Revealed type is int, but should be str https://mypy-play.net/?mypy=latest&python=3.11&gist=011c7d73769c1d028b4d4bfa8a30155d If this bug is fixed, mypy will correctly infer from typeshed's stub for |
Fixing that bug may be quite disruptive; I expect we'll have to get much stricter in typeshed about adding |
I'd like to have a go, anyway, and see what mypy_primer says. I have some ideas :) |
(I created a new label for mypy issues that are known to cause issues for mypyc users.) |
Fixes #14056 #14056 was originally reported as a mypyc issue (because that's how it presented itself to the user), but the underlying bug is really a bug to do with how mypy understands metaclasses. On mypy `master`: ```py class Meta(type): bar: str class Foo(metaclass=Meta): bar: int reveal_type(Foo().bar) # Revealed type is int (correct!) reveal_type(Foo.bar) # Revealed type is int, but should be str ``` This PR fixes that incorrect behaviour. Since this is really a mypy bug rather than a mypyc bug, I haven't added a mypyc test, but I'm happy to if that would be useful. (I'll need some guidance as to exactly where it should go -- I don't know much about mypyc internals!)
Bug Report
It looks mypy's type inference works fine and it's mypyc (maybe) bug
Maybe it's connected to builtins
vars
signature -- vars by the signature should returndict
But it's false,
vars
may returnmappingproxy
:To Reproduce
Then build it via mypy:
And run it
Expected Behavior
Actual Behavior
Your Environment
mypy-1.0.0+dev.dbcbb3f5c3ef791c98088da0bd1dfa6cbf51f301
(latest@git)mypy.ini
(and other config files): emptyThe text was updated successfully, but these errors were encountered: