Skip to content
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

Don't generate trivial __new__ #1555

Closed
serhiy-storchaka opened this issue Dec 15, 2016 · 3 comments
Closed

Don't generate trivial __new__ #1555

serhiy-storchaka opened this issue Dec 15, 2016 · 3 comments

Comments

@serhiy-storchaka
Copy link

Cython generates the __new__ method even for classes without data. Recent change in CPython broke multiple inheritance from Cython classes. That change was reverted for backward compatibility, but if Cython would not generate trivial __new__ for empty classes, it would help to push that change back.

@scoder scoder added this to the 3.0 milestone Mar 19, 2019
@scoder
Copy link
Contributor

scoder commented Mar 22, 2019

@serhiy-storchaka, I'm not sure what to make of this. Cython does not generate a __new__ Python method directly. It only generates a tp_new slot function. CPython then generates the __new__ method wrapper for it.

If Cython left tp_new empty, then the type couldn't be instantiated. So a tp_new, even an empty one that calls the base type's tp_new, is always needed.

We could try to inherit the tp_new function of the base type instead of creating an empty one that calls it, but I don't know if that changes anything. Is that what you were referring to?

@scoder
Copy link
Contributor

scoder commented Mar 22, 2019

Also, for a type without base types, we could then use PyType_GenericNew for tp_new, but that doesn't seem to be special-cased anywhere. There doesn't seem to be a benefit to that, so is this only about a tp_new that calls the base class tp_new, i.e. subtypes that do not add anything to tp_new ?

@scoder
Copy link
Contributor

scoder commented Mar 31, 2019

#2900 and #2909 should resolve this.

@scoder scoder closed this as completed Mar 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants