[ python-Bugs-1294232 ] Error in metaclass search order
SourceForge.net
noreply at sourceforge.net
Mon Sep 19 02:42:20 CEST 2005
Bugs item #1294232, was opened at 2005-09-18 01:07
Message generated for change (Comment added) made by pwerneck
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1294232&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Type/class unification
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Pedro Werneck (pwerneck)
Assigned to: Nobody/Anonymous (nobody)
Summary: Error in metaclass search order
Initial Comment:
In a simple class hierarchy, I have class A with
metaclass M_A and class B, subclass of A, with
metaclass M_B, subclass of M_A, as required.
A new class C, subclass of B, must have M_B or a
subclass of it as subclass, or a TypeError, metaclass
conflict exception is raised. The exception is raised
in a multiple class hierarchy (diamond, trees, etc) or
in a single class hierarchy when using a metaclass with
no relation to M_A and M_B.
If M_A or type are used as C metaclass, the interpreter
is ignoring dict['__metaclass__'], which has priority
over B.__class__ and using M_B, when it was supposed to
raise TypeError, with the "metaclass conflict" error
message.
More details in attached file.
----------------------------------------------------------------------
>Comment By: Pedro Werneck (pwerneck)
Date: 2005-09-19 00:42
Message:
Logged In: YES
user_id=696687
Yes. I think this confusion was caused because of the lack
of documentation on this topic, especially on the case
described here, which seems to break some rules.
Since the "Unifying types and classes" essay seems to be the
most used Python document about this topic and, I suggest
the first rule on determining a metaclass be changed from:
"If dict['__metaclass__'] exists, it is used."
To something like:
"If dict['__metaclass__'] exists and is equal to, or a
subclass of, each of the metaclasses of the bases, it is
used; if it exists and is a base class of any metaclass of
the bases, the most specialized metaclass in the hierarchy
is used; if it exists and doesn't satisfies any of these
constraints, TypeError is raised."
----------------------------------------------------------------------
Comment By: Rodrigo Dias Arruda Senra (rodsenra)
Date: 2005-09-18 23:04
Message:
Logged In: YES
user_id=9057
I have discussed this at length with Pedro Werneck by email.
I personally believe the best path to follow is to document
that
the entity specified in __metaclass__ inside C class body, can
be automagically replaced by the most specialized metaclass
among
the metaclasses associated to C ancestors. I think that will
suffice for
the meta-adventurous.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1294232&group_id=5470
More information about the Python-bugs-list
mailing list