How to annotate generic class with ParamSpec
argument in older versions
#908
Replies: 3 comments 5 replies
-
This line: class IntsInvoker(Invoker[[int, int]]): must be spelled like this:
|
Beta Was this translation helpful? Give feedback.
-
Looks like we skipped this in typing-extensions tests: https://github.com/python/typing/blob/master/typing_extensions/src_py3/test_typing_extensions.py#L2075. I don't recall how hard we tried to get this to work, but perhaps it's possible with some more black magic in typing_extensions. |
Beta Was this translation helpful? Give feedback.
-
The solutions in https://mypy.readthedocs.io/en/latest/runtime_troubles.html#using-classes-that-are-generic-in-stubs-but-not-at-runtime should be applicable here as well |
Beta Was this translation helpful? Give feedback.
-
Let's say I have something along these lines (this is completely contrived) and I'm using Python 3.9:
According to PEP-612, the above should be valid. However, if I run this using Python 3.9 or lower, it will crash with:
I should also be able to define
IntsInvoker
in this way:However that also crashes using Python 3.9 or lower:
What is the proper way to define
IntsInvoker
so it will work in Python 3.9 and 3.10?Beta Was this translation helpful? Give feedback.
All reactions