[issue15402] Correct __sizeof__ support for struct

Martin v. Löwis report at bugs.python.org
Thu Jul 26 16:41:11 CEST 2012


Martin v. Löwis <martin at v.loewis.de> added the comment:

> What if use totalsize = object.__sizeof__(struct_obj) ?

That would defeat the purpose of the test. We want to test whether __sizeof__ is correct, so we shouldn't use __sizeof__ in the test to compute the expected result. I understand that object.__sizeof__ is actually a different implementation, but still: there might be errors e.g. in the type definition that cancel out errors in the sizeof implementation. The more "directly" the expected result is computed, the better.

I also realize that such tests will be fragile if the the structures change. This is a good thing, IMO: anybody changing the layout of some object should *have* to verify that the size computation is still correct, so it's good that the test breaks if the structures change.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15402>
_______________________________________


More information about the Python-bugs-list mailing list