A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2012-October/122241.html below:

[Python-Dev] return type of __complex__

[Python-Dev] return type of __complex__ [Python-Dev] return type of __complex__Antonio Cuni anto.cuni at gmail.com
Fri Oct 19 15:08:40 CEST 2012
Hi,

while fixing pypy to pass CPython 3.2 tests, I found what I think it's a
inconsistency in how CPython (both 2.7 and 3.2) handles __complex__:

>>> class Obj:
...     def __complex__(self):
...         return 2.0
...
>>> obj = Obj()
>>> complex(obj)
(2+0j)
>>>
>>> import cmath
>>> cmath.acos(obj)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __complex__ should return a complex object


i.e., the complex constructor does not check that __complex__ returns an
actual complex, while the cmath functions do.
To me it looks like a bug in complex_new which should do the check as well;
however, there is a test in test_complex.test_constructor which checks that
returning a float actually works.

Is that the real intended behavior?

ciao,
Anto
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4