a type without a __mro__?
John Lenton
john at grulic.org.ar
Sun Feb 6 01:39:09 EST 2005
On Sat, Feb 05, 2005 at 11:37:10AM +0100, Alex Martelli wrote:
> Can anybody suggest where to find (within the standard library) or how
> to easily make (e.g. in a C extension) a type without a __mro__, except
> for those (such as types.InstanceType) which are explicitly recorded in
> the dispatch table copy._deepcopy_dispatch...?
would this do what you need?
class C(type):
def __getattribute__(self, attr):
if attr == '__mro__':
raise AttributeError, "What, *me*, a __mro__? Nevah!"
return super(C, self).__getattribute__(attr)
class D(object):
__metaclass__ = C
instances of D have a type that behaves as if it didn't have a
__mro__. This isn't exactly what you asked for, but it might be
enough.
--
John Lenton (john at grulic.org.ar) -- Random fortune:
El tiempo cura los dolores y las querellas porque cambiamos. Ya no somos la
misma persona.
-- Blaise Pascal. (1600-1662) Filósofo y escritor francés.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20050206/f6ec962e/attachment.sig>
More information about the Python-list
mailing list