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-487 #2781

Open
fduxiao opened this Issue Jan 4, 2019 · 3 comments

Comments

Projects
None yet
2 participants
@fduxiao
Copy link

fduxiao commented Jan 4, 2019

class ABC:
    def __init_subclass__(cls):
        print(cls)


class SubClass(ABC):
    pass

If you run this with python directly, it gives:

<class '__main__.SubClass'>

But after I compile it with cython, it gives:

TypeError                                 Traceback (most recent call last)
<ipython-input-1-a0954f22e2a4> in <module>
----> 1 import test

test.pyx in init test()

TypeError: __init_subclass__() takes exactly one argument (0 given)

How to solve it?

@scoder scoder changed the title Wrong cythonization for __init_subclass Implement PEP-487 Jan 4, 2019

@scoder scoder added this to the 3.0 milestone Jan 4, 2019

@scoder

This comment has been minimized.

Copy link
Contributor

scoder commented Jan 4, 2019

The relevant bits of PEP-487 need to get implemented. Specifically, __init_subclass__() is an implicit class method and must be treated as such, and class creation should call the __init_subclass__() method in older Python versions (before 3.6).

I assume you were using Py3.6 or later for your tests, right?

@scoder scoder added the help wanted label Jan 4, 2019

@fduxiao

This comment has been minimized.

Copy link

fduxiao commented Jan 4, 2019

@scoder Yes, and actually with the latest python 3.7.2. I need this feature because metaclass cannot be passed from an ancestor class, so I choose to use __init_subclass__ instead to control the behavior of a class.

@scoder

This comment has been minimized.

Copy link
Contributor

scoder commented Jan 4, 2019

PR welcome, seems relatively easy. If you want to give it a try, see the HackerGuide for hints how to get started, and ask on the cython-dev mailing list whenever you feel like needing help.

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