GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-125783: Add more tests to prevent regressions with the combination of ctypes and metaclasses. by junkmd · Pull Request #126126 · python/cpython Conversation
|
| # Test for modern metaclass initialization that does not | ||
| # require recursion avoidance. | ||
|
|
||
| class ct_meta(type): | ||
| def __init__(self, name, bases, namespace): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
super().__init__ call when subclassing.__new__.| # Test for modern metaclass initialization that does not | |
| # require recursion avoidance. | |
| class ct_meta(type): | |
| def __init__(self, name, bases, namespace): | |
| class ct_meta(type): | |
| def __init__(self, name, bases, namespace): | |
| super().__init__(name, bases, namespace) | |
| # Avoid recursion. | |
| # (See test_creating_pointer_in_dunder_new_1) | |
| if bases == (c_void_p,): | |
| return | |
| if issubclass(self, PtrBase): | |
| return |
(And similar in test_creating_pointer_in_dunder_init_2.)
The reason you don't need recursion avoidance here is that the internal PyCSimpleType is not set up for diamond inheritance patterns, and doesn't call super().__init__ (that is, ct_meta.__init__ here). That's arguably a bug. (It definitely would be one if we wanted to support such subclassing.)
If you switch the metaclass bases, writing class p_meta(ct_meta, PyCSimpleType), recursion avoidance becomes necessary again.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Good catch! thank you.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I realized that with |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I built In #125783, I said:
However, this was because I had overlooked |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…nation of ctypes and metaclasses. (pythonGH-126126) (cherry picked from commit 6c67446) Co-authored-by: Jun Komoda <[email protected]>
|
GH-126275 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…nation of ctypes and metaclasses. (pythonGH-126126) (cherry picked from commit 6c67446) Co-authored-by: Jun Komoda <[email protected]>
|
GH-126276 is a backport of this pull request to the 3.12 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…nation of ctypes and metaclasses. (pythonGH-126126)
…nation of ctypes and metaclasses. (pythonGH-126126)
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.