You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: typing_extensions.Generic not support TypeVar defaults #672
The assertions you listed differ in both cases. I would think one wants the same code in both cases?
(str, int) is the current behavior on Python 3.13 / 3.14.
Under typing_extensions 4.14.1 it returns only (str,) with 4.15.0 it also returns the default value similar to 3.13 typing.
To my knowledge it is the intended behavior to get the all arguments get_args with defaults substituted in.
Based on a cursor look with a debugger, the behavior difference comes from inside Generic.__class_getitem__. Fixing this might require monkey patching it on Python 3.9 & 3.10
@jacksonthall22 that's unrelated (your example doesn't involve typing-extensions). You need to call get_args() on the class, not an instance.
@IvanKirpichnikov PRs welcome! We'll have to see how invasive the fix is; it only affects 3.9 (which is about to go EOL) and 3.10 (which is also getting towards the end of its support).
@IvanKirpichnikov PRs welcome! We'll have to see how invasive the fix is; it only affects 3.9 (which is about to go EOL) and 3.10 (which is also getting towards the end of its support).
I didn't understand the argument about 3.10. Type var defaults appeared in 3.13.
That is, you need to make your typing_extensions.Generic to EOL 3.13. No?
If I understand the previous discussion correctly, this bug appears only in 3.9 and 3.10. If it instead appears up to 3.12, that does make it more important to fix.
On Python 3.11 and 3.12 with typing-extensions, get_args() returns the same thing as on 3.13+ with typing (as @brianschubert reported a few comments up). If you think something is still wrong on 3.11 and 3.12, please report exactly what you expect to happen and what is happening instead.
because typing_extensions.Generic is literally typing.Generic
That's an implementation detail; we don't necessarily have to duplicate Generic itself to solve this issue. We care only about the publicly visible behavior.
Activity
Daraan commentedon Sep 3, 2025
The assertions you listed differ in both cases. I would think one wants the same code in both cases?
(str, int) is the current behavior on Python 3.13 / 3.14.
Under typing_extensions 4.14.1 it returns only
(str,)with 4.15.0 it also returns the default value similar to 3.13typing.To my knowledge it is the intended behavior to get the all arguments
get_argswith defaults substituted in.brianschubert commentedon Sep 3, 2025
This only seems to affect typing_extensions on Python 3.9 and 3.10. This script:
produces:
Based on a cursor look with a debugger, the behavior difference comes from inside
Generic.__class_getitem__. Fixing this might require monkey patching it on Python 3.9 & 3.10IvanKirpichnikov commentedon Sep 4, 2025
I think we don't need monkey pathing here. It is enough to write your own
Genericobject that will be able to useTypeVardefaultsAt the moment,
typing_extensionsuses the mechanism of re-exporting theGenericclass from the originaltypingpackageIvanKirpichnikov commentedon Sep 13, 2025
Is there any news on this bug? Should I send a pull request with a bug fix?
jacksonthall22 commentedon Oct 9, 2025
MRE with the new generics syntax:
JelleZijlstra commentedon Oct 10, 2025
@jacksonthall22 that's unrelated (your example doesn't involve typing-extensions). You need to call
get_args()on the class, not an instance.@IvanKirpichnikov PRs welcome! We'll have to see how invasive the fix is; it only affects 3.9 (which is about to go EOL) and 3.10 (which is also getting towards the end of its support).
IvanKirpichnikov commentedon Oct 11, 2025
I didn't understand the argument about 3.10. Type var defaults appeared in 3.13.
That is, you need to make your typing_extensions.Generic to EOL 3.13. No?
JelleZijlstra commentedon Oct 11, 2025
If I understand the previous discussion correctly, this bug appears only in 3.9 and 3.10. If it instead appears up to 3.12, that does make it more important to fix.
IvanKirpichnikov commentedon Oct 11, 2025
It appears on versions <3.13(that is 3.10, 3.11, 3.12) because
typing_extensions.Genericis literallytyping.GenericI think this option is critical because it requires working with default value options in input extensions.
JelleZijlstra commentedon Oct 11, 2025
On Python 3.11 and 3.12 with typing-extensions,
get_args()returns the same thing as on 3.13+ with typing (as @brianschubert reported a few comments up). If you think something is still wrong on 3.11 and 3.12, please report exactly what you expect to happen and what is happening instead.That's an implementation detail; we don't necessarily have to duplicate Generic itself to solve this issue. We care only about the publicly visible behavior.