a type without a __mro__?

Nick Coghlan ncoghlan at iinet.net.au
Sat Feb 5 10:06:01 EST 2005


Fredrik Lundh wrote:
> 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...?
> 
> 
> something like this?
> 
> 
>>>>import re
>>>>x = re.compile("")
>>>>x
> 
> <_sre.SRE_Pattern object at 0x00B2F7A0>
> 
>>>>x.__mro__
> 
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> AttributeError: __mro__
> 
>>>>import copy
>>>>type(x) in copy._deepcopy_dispatch
> 
> False
> 
> </F> 

Unfortunately, it *does* have a __deepcopy__ method, so I don't think it 
actually triggers the bug Alex is interested in:

Py> import re
Py> x = re.compile("")
Py> x.__mro__
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
AttributeError: __mro__
Py> from copy import deepcopy
Py> deepcopy(x)
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
   File "C:\Python24\lib\copy.py", line 172, in deepcopy
     y = copier(memo)
TypeError: cannot deepcopy this pattern object
Py> x.__deepcopy__
<built-in method __deepcopy__ of _sre.SRE_Pattern object at 0x00B242C0>

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net



More information about the Python-list mailing list