gh-108946: correctly calculate most specific metaclass#108949
Conversation
|
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
|
Could you review this PR @AlexWaygood? |
AlexWaygood
left a comment
There was a problem hiding this comment.
Could you review this PR @AlexWaygood?
Not sure why I'm getting pinged here specifically, but sure! :)
This PR doesn't appear to do what it says it's doing. I rebuilt Python with your PR branch, and exactly the same exception is raised that you reported in #108946:
Running Debug|x64 interpreter...
Python 3.13.0a0 (heads/patch-2:414a44dd80, Oct 4 2023, 16:11:24) [MSC v.1932 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class Meta1(type): pass
...
>>> class Meta2(type): pass
...
>>> class Meta3(Meta1, Meta2): pass
...
>>> class Class1(metaclass=Meta1): pass
...
>>> class Class2(metaclass=Meta2): pass
...
>>> class Class3(metaclass=Meta3): pass
...
>>> class Conflict(Class1, Class2, Class3): pass
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its basesAnd I'd expect that to be the case. The exception you reported in #108946 isn't raised from a function in types.py -- you can tell that from the fact that types.py doesn't appear anywhere in the traceback. It's raised here:
Lines 3119 to 3125 in bf4bc36
The function you're tweaking in types.py is a helper function for the types.prepare_class function, which is a pure-Python emulation of the logic that takes place in Objects/typeobject.c. It's not actually involved in creating classes through the class statement; it's just a standard-library function to aid people who want to dynamically create classes for whatever reason.
Even if this PR worked correctly, we'd be unable to merge it unless you wrote some tests for it :) Tests would also have been helpful for you, as they would have alerted you to the fact that your PR wasn't working in the way you'd intended.
N.B. If you don't know how to build Python from source or run tests, there's a lot of great information on that in the devguide! https://devguide.python.org
|
This PR is stale because it has been open for 30 days with no activity. |
|
Closing since it's been 3 years and my review comments were not addressed. Feel free to open a new PR if you're still interested in this issue! |


This PR fixes #108946 by finding the most specific single metaclass among all
bases, instead of raising an exception in the middle of the_calculate_meta