question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implement PEP-560: core support for generic types

See original GitHub issue

Seems 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:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:19 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
scodercommented, Apr 9, 2020
0reactions
gstcommented, Feb 11, 2021

I confirm the workaround works… it’s not very nice but it works. Thanks for it 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found