Improve metaclass conflict error message with clearer terminology and contextual information #134902
Labels
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
type-feature
A feature request or enhancement
Uh oh!
There was an error while loading. Please reload this page.
Feature or enhancement
Proposal:
Improve Metaclass Conflict Error Message
Summary
Improve the error message raised during metaclass conflicts to specify the
base with incompatible metaclass.
Motivation
Class inheritance has a well-established terminology across languages, but
Python's metaclass system introduces a distinct mechanism that lacks clear
linguistic conventions. This feature proposes the following
terminologies.
Example
In the following code,
MetaFoo
andMetaBar
are both subclasses oftype
making them metaclasses according to the previous terminology suggestion.
Since neither is a subclass of the other, they are incompatible as metaclasses.
Foo
derives fromMetaFoo
andBar
derives fromMetaBar
, but becauseBar
is based onFoo
; the conflicting metaclasses cause theTypeError
relating to metaclass conflict.
Current Behaviour
The
TypeError
currently raised looks like this:Proposed Behaviour
The improved error message would add contextual details and adopt the new
terminology: (Line breaks included for clarity).
Notes
This change requires changes to the
_PyType_CalculateMetaclass
function only.Including the name (
Bar
in the example) in the error message would requirechanges to multiple functions across the codebase.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
The text was updated successfully, but these errors were encountered: