You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
type(MetaclassOverride) # returns 'type' or custom metaclass
type(ChildClass) # returns the built-in pybind11 type
In standard Python, when a subclass is registered without specifying a metaclass, it would automatically inherit the parent’s metaclass. In the current pybind case, however, the subclass gets a different type, which would normally be considered a metaclass conflict in Python.
Do I understand correctly that we would need to carry the metaclass together with the base class everywhere in order to always register subclasses with the same metaclass, or am I mistaken? In general, I wouldn’t want to have to carry the metaclass throughout all my code and be aware of it. I’m not sure whether to treat the current case as a bug, a proposed improvement, or just a feature of how it works.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, we have a class registered with a metaclass:
We want to register a subclass of this class without explicitly specifying a metaclass
What Python returns with this registration:
In standard Python, when a subclass is registered without specifying a metaclass, it would automatically inherit the parent’s metaclass. In the current pybind case, however, the subclass gets a different type, which would normally be considered a metaclass conflict in Python.
Do I understand correctly that we would need to carry the metaclass together with the base class everywhere in order to always register subclasses with the same metaclass, or am I mistaken? In general, I wouldn’t want to have to carry the metaclass throughout all my code and be aware of it. I’m not sure whether to treat the current case as a bug, a proposed improvement, or just a feature of how it works.
Beta Was this translation helpful? Give feedback.
All reactions