| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
| # 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.
| # 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 a problem hiding this comment.
Good catch! thank you.
Sorry, something went wrong.
|
I realized that with super().__init__ and recursion limits, this test might pass in Python 3.12 as well. |
Sorry, something went wrong.
|
I built 3.12 locally and ran this test, and it passed without any errors. In #125783, I said:
However, this was because I had overlooked super().__init__ and the recursion limits. |
Sorry, something went wrong.
…nation of ctypes and metaclasses. (pythonGH-126126) (cherry picked from commit 6c67446) Co-authored-by: Jun Komoda <45822440+junkmd@users.noreply.github.com>
|
GH-126275 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
…nation of ctypes and metaclasses. (pythonGH-126126) (cherry picked from commit 6c67446) Co-authored-by: Jun Komoda <45822440+junkmd@users.noreply.github.com>
|
GH-126276 is a backport of this pull request to the 3.12 branch. |
Sorry, something went wrong.
…nation of ctypes and metaclasses. (pythonGH-126126)
…nation of ctypes and metaclasses. (pythonGH-126126)
| Back | FazBrowse Home | New Git URL |
In #125881, tests were added for generating pointer types in __new__ of metaclasses.
This time, I've added tests for generating pointer types in __init__ of metaclasses.
This is internal-only, so I don’t think it needs a NEWS entry.
I would like to backport this to 3.13 as well.
Please see also #125783 (comment).