Change the typing spec around string references by davidhalter · Pull Request #2144 · python/typing
@JelleZijlstra Could you please pre-review this? What do you think about this spec change?
I think I have integrated all the changes. Is it time to open an issue on the Typing Council’s issue tracker asking for a decision?
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One wording nit, one formatting nit, and one conformance suite nit :) But overall this looks great to me.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me - much more consistent and clearly specified than before
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Thanks @davidhalter for getting this clarified.
I have integrated all of Carl's suggestions. I will update the conformance tests as soon as the typing council approves this change. If I update it now we probably just run into merge conflicts, since especially pyrefly changes a lot.
@carljm Please let me know if you think something needs more work.
sk-
mentioned this pull request
2 tasks
Hi, can someone explain the intent of this change to me?
Given, under python 3.14:
Python 3.14.0 (main, Oct 20 2025, 16:44:45) [GCC 14.3.1 20250808 (Red Hat 14.3.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class A: pass
...
>>> class X:
... def A(self) -> "A": pass
...
>>> class Y:
... def A(self) -> A: pass
...
>>> typing.get_type_hints(X.A)
{'return': <class '__main__.A'>}
>>> typing.get_type_hints(Y.A)
{'return': <function Y.A at 0x7f2052bc3c10>}
>>>
does this change propose that it would be impossible for get_type_hints(X.A) to return class A under any circumstances, even with the quotes?
are you going to change the behavior of get_type_hints() ? is this a 3.15 change? is there a pep? it should be apparent that this is an enormous backwards-incompatible change I hope?
edit: the pep is pep-749
existing libraries which use this pattern will have to use:
>>> _a_cls = A
>>> class Z:
... def A(self) -> _a_cls: pass
...
>>> typing.get_type_hints(Z.A)
{'return': <class '__main__.A'>}
this would be on top of this breaking change in 3.13 -> 3.14
Python 3.13.9 | packaged by Anaconda, Inc. | (main, Oct 21 2025, 19:09:58) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class A: pass
...
>>> class F:
... def A(self)->A: pass
...
>>> import typing
>>> typing.get_type_hints(F.A)
{'return': <class '__main__.A'>}
Python 3.14.3 | packaged by Anaconda, Inc. | (main, Feb 24 2026, 22:45:56) [MSC v.1942 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class A: pass
...
>>> class F:
... def A(self) -> A: pass
...
>>> import typing
>>> typing.get_type_hints(F.A)
{'return': <function F.A at 0x0000025520D22610>}