-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Calling typing.get_type_hints with a class or instance method with PEP 695 type parameters fails if PEP 563 is enabled #124089
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
Comments
Can replicate it on
I will take a look, thanks for the report. |
From the first sight - there's not much of what can be done, because There are literally no ways of accessing Except for this piece of hackery: I think that we might need some special handling for this. |
I don't think we should change anything here. In the meantime, if you want reliable runtime introspection, don't use |
(Not sure if worth its own bug report so I am adding here.) This issue also affects quoted forward references to PEP695-style generic types: from typing import get_type_hints
class Foo[T]:
def foo(self) -> "Bar[T]":
...
class Bar[T]:
def bar(self, _: T) -> None:
...
get_type_hints(Foo[int].foo) # NameError: name 'T' is not defined (Is this because Hopefully this is all fixed by PEP649 in 3.14 🤞 Out of curiosity, I tested reveal_type(Foo[int].foo) # Revealed type is "def (self: Foo[T`1]) -> Bar[T`1]" Much better result with reveal_type(Foo[int].foo) # Type of "Foo[int].foo" is "(self: Foo[int]) -> Bar[int]" |
@ncanceill yes, that seems like the same thing. |
Bug report
Bug description:
This seems very similar to #114053, but with class methods (or instance methods, the result is the same) instead of classes themselves.
Removing the
from __future__ import annotations
import works fine:Using the pre PEP-695 syntax, with or without
from __future__ import annotations
, works fine as well:This happens on both 3.12.5 and 3.13.0rc2
CPython versions tested on:
3.12, 3.13
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered: