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

Implement PEP-560 #2753

Open
vvegorova opened this Issue Dec 10, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@vvegorova
Copy link

vvegorova commented Dec 10, 2018

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

@scoder

This comment has been minimized.

Copy link
Contributor

scoder commented Dec 29, 2018

PEP-560 is not currently implemented. Probably easy to do, but needs to be done.
https://www.python.org/dev/peps/pep-0560/

@scoder scoder changed the title typing.Generic[T] doesn't work after cythonization for python 3.7 Implement PEP-560 Dec 29, 2018

@scoder scoder added this to the 3.0 milestone Dec 29, 2018

@scoder

This comment has been minimized.

Copy link
Contributor

scoder commented Dec 29, 2018

This should be relatively easy.

  • copy over the tests from CPython
  • run the tests to see what C code gets generated currently
  • copy over parts of the implementation from CPython, drop them in the right places according to the C code generated for the tests (probably just the part from CPython's abstract.c)
  • adapt and optimise.
@scoder

This comment has been minimized.

Copy link
Contributor

scoder commented Jan 16, 2019

PR welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment