Implement PEP-560: core support for generic types
See original GitHub issueSeems that Generic.__class_getitem__
can’t be called automatically after cythonization.
Code sample example.py
:
from typing import Generic, TypeVar
T = TypeVar("T")
print(Generic[T])
Cythonization:
cythonize -a -i example.py
The cythonized code fails with TypeError
:
>>> import example
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "example.py", line 5, in init example
print(Generic[T])
TypeError: 'type' object is not subscriptable
Cython 0.29.1 Python 3.7.1
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:19 (8 by maintainers)
Top Results From Across the Web
PEP 560 – Core support for typing module and generic types
PEP 560 – Core support for typing module and generic types. Author: Ivan Levkivskyi <levkivskyi at gmail.com>; Status: Accepted; Type: Standards Track ...
Read more >[issue32226] Implement PEP 560: Core support for typing module ...
[issue32226] Implement PEP 560: Core support for typing module and generic types ... It should save at least one pointer comparison for base...
Read more >PEP 560: Core support for generic types (#411) · 1c3d85cc5e - peps ...
PEP: 560. Title: Core support for generic types. Author: Ivan Levkivskyi <levkivskyi@gmail.com>. Status: Draft. Type: Standards Track.
Read more >Why are generics in Python implemented using __ ...
Without __class_getitem__ generics requires a metaclass, ... See the original PEP 560 - Core support for typing module and generic types ...
Read more >Python 3.7 — MicroPython 1.19 documentation - OpenMV Docs
Data Classes. PEP 560. Core support for typing module and generic types ... math.remainder() added to implement IEEE 754-style remainder.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
See https://github.com/cython/cython/issues/2753#issuecomment-450492882 above. PR welcome.
I confirm the workaround works… it’s not very nice but it works. Thanks for it 😃