Skip to content
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

Concatenate implementation generates runtime exception if parameterized by ... #48

Open
erictraut opened this issue Jun 9, 2022 · 3 comments
Labels

Comments

@erictraut
Copy link

The following code should work without a runtime exception.

from typing import Any, Callable
from typing_extensions import ParamSpec, Concatenate


P = ParamSpec("P")
MyAlias = Callable[Concatenate[int, P], Any]

x: MyAlias[...]

It runs fine on Python 3.10 if using typing.Concatenate but fails on Python 3.9 if using typing_extensions.Concatenate. The runtime exception is:

TypeError: Parameters to generic types must be types. Got Ellipsis.
@Fidget-Spinner
Copy link
Member

Fidget-Spinner commented Jul 7, 2022

This seems like a bug in Python's typing module itself.

# In 3.9
typing.Callable[T, int][...]

TypeError: Parameters to generic types must be types. Got Ellipsis.

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.

@Fidget-Spinner
Copy link
Member

Fidget-Spinner commented 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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants