Why does 2.3a2 change "slots" in complex?
glc at well.com
Sat Mar 1 18:00:17 CET 2003
On Fri, 28 Feb 2003 22:03:45 -0500, mertz at gnosis.cx (David Mertz) wrote:
>One of the unit tests involves adding extra attributes to descendents of
>standard data types. It turns out, that test breaks with Python 2.3a2,
>because of a change in the implementation of complex.
>Here is a brief test case that shows the behavior. I am interested in
>why this change was made. Is it a bug or a feature? If a feature, what
>benefit does this have? If a bug... well, I guess that's the point of
>an alpha version.
If you check the type of c in your example, you'll find that it is complex under
2.3a2 (rather than __main__.Complex).
I believe this is definitely a bug. It appears this problem was introduced by a
change which causes the complex constructor (complex_new) to return its argument
if it is of the exact type complex (rather than creating a new complex
instance). Instead, I believe complex_new should also check to see if the type
being constructed (i.e., the type parameter) is in fact exactly complex; if not,
then it should try to create the new instance no matter what arguments it gets.
I believe the correct fix would be to change this test:
if (PyComplex_CheckExact(r) && i == NULL)
if (PyComplex_CheckExact(r) && i == NULL && PyComplex_CheckExact(type))
I'll file a bug report.
More information about the Python-list