Mark Dickinson <dicki...@gmail.com> added the comment: So there's a hint about what's happening here at the bottom of the section
http://docs.python.org/reference/datamodel.html#id5 of the docs, where it says: """In the current implementation, the built-in numeric types int, long and float do not use coercion; the type complex however does use it. The difference can become apparent when subclassing these types. Over time, the type complex may be fixed to avoid coercion. [...]""" In the OPs example, when z + xz is evaluated, xz is (successfully) coerced to type complex, and then complex.__add__ is called to do the addition as usual. There's definitely (at least) a documentation bug here, given that at the same place as referenced above it says: """New-style classes (those derived from object) never invoke the __coerce__() method in response to a binary operator; the only time __coerce__() is invoked is when the built-in function coerce() is called.""" At the level of the C code, the practical difference between complex and (for example) float is that the float type has Py_TPFLAGS_CHECKTYPES set, and all arithmetic operations do their own conversions. The complex type doesn't set Py_TPFLAGS_CHECKTYPES, and so (contrary to the documentation) relies on complex_coerce to do any conversions. _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue3734> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com