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
Concatenate implementation generates runtime exception if parameterized by ... #48
This seems like a bug in Python's typing module itself.
# In 3.9typing.Callable[T, int][...]
TypeError: Parameterstogenerictypesmustbetypes. GotEllipsis.
The problem is that Callable uses the default _GenericAlias's substitution behavior pre 3.10. Which means its checks are too restrictive. We had to intentionally loosen the checks in 3.10 to get around this.
I don't think we can fix this from typing_extensions unless we monkey patch typing._GenericAlias.__getitem__ (or typing._type_check). I don't feel too good doing that though.
Also, we're sadly past the stage for bugfixes in 3.9. I suggest that we add this to the known limitations in the README and (unfortunately) close as can't fix.
I am currently looking at this again and the statement that "It runs fine on Python 3.10 if using typing.Concatenate" confused be a bit.
In hindsight this should only hold for 3.10.0-3.10.2 afterwards it also does not run on the other 3.10 typing versions either.
Edit: Monkey patching copy_with of _ConcatenateGenericAlias to the 3.11 variant would be sufficient for the 3.10 versions.
Edit2: Also doable without monkey patch in 3.10.
#479 covered this Issue only for 3.10, or rather 3.10.3+.
For 3.8 & 3.9 I see no other way around monkey patching typing._GenericAlias.__getitem__ to fix this issue.
The essential part of the monkey patch could be similar to this, maybe with more checks on the origin:
- params = tuple(_type_check(p, msg) for p in params)+ params = tuple(typing._type_check(p, msg) if p is not ... else ...+ for p in params)
Activity
Fidget-Spinner commentedon Jul 7, 2022
This seems like a bug in Python's typing module itself.
The problem is that
Callableuses the default_GenericAlias's substitution behavior pre 3.10. Which means its checks are too restrictive. We had to intentionally loosen the checks in 3.10 to get around this.I don't think we can fix this from
typing_extensionsunless we monkey patchtyping._GenericAlias.__getitem__(ortyping._type_check). I don't feel too good doing that though.Fidget-Spinner commentedon Jul 7, 2022
Also, we're sadly past the stage for bugfixes in 3.9. I suggest that we add this to the known limitations in the README and (unfortunately) close as can't fix.
JelleZijlstra commentedon May 22, 2023
This is now documented as a limitation at https://typing-extensions.readthedocs.io/en/latest/#Concatenate. If there is a reasonable way to fix it, I'd accept a PR.
Daraan commentedon Oct 3, 2024
I am currently looking at this again and the statement that "It runs fine on Python 3.10 if using typing.Concatenate" confused be a bit.
In hindsight this should only hold for 3.10.0-3.10.2 afterwards it also does not run on the other 3.10
typingversions either.Edit: Monkey patchingcopy_withof_ConcatenateGenericAliasto the 3.11 variant would be sufficient for the 3.10 versions.Edit2: Also doable without monkey patch in 3.10.
Daraan commentedon Oct 22, 2024
As a summary:
#479 covered this Issue only for 3.10, or rather 3.10.3+.
For 3.8 & 3.9 I see no other way around monkey patching
typing._GenericAlias.__getitem__to fix this issue.The essential part of the monkey patch could be similar to this, maybe with more checks on the origin: