[issue3122] sys.getsizeof() gives an AttributeError for _sre objects.
Amaury Forgeot d'Arc
report at bugs.python.org
Fri Jun 27 00:09:36 CEST 2008
Amaury Forgeot d'Arc <amauryfa at gmail.com> added the comment:
I wondered why getsizeof fails for _sre.SRE_Pattern objects when it
succeeds for _socket.socket or struct.Struct.
It turns out that _sre.SRE_Pattern defines the tp_getattr slot, and this
prevents attribute lookup from searching the base class (object).
This is a pity, because the base implementation (which use tp_basicsize)
does the right thing for many objects.
So I borrowed some code from the __format__ method, and here is a patch.
Now classes are not handled specially any more; the distinction is
between old-style instances, and all other objects.
All tests pass, but I may have missed something important...
----------
nosy: +amaury.forgeotdarc
Added file: http://bugs.python.org/file10746/sizeof.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3122>
_______________________________________
More information about the Python-bugs-list
mailing list