New submission from David Vo <david....@gmail.com>:
If math.copysign(x, y) is passed an x that cannot be converted to a float and a y that implements __float__() in Python, math.copysign() will raise a SystemError from the TypeError resulting from the attempted float conversion of x. math.copysign() should probably return immediately if converting the first argument to a float raises an error. Example: >>> import math >>> from fractions import Fraction >>> float(Fraction(-1, 1)) # this is needed to avoid an AttributeError? -1.0 >>> math.copysign((-1) ** 0.5, Fraction(-1, 1)) TypeError: can't convert complex to float The above exception was the direct cause of the following exception: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.8/numbers.py", line 291, in __float__ return self.numerator / self.denominator SystemError: PyEval_EvalFrameEx returned a result with an error set ---------- components: Extension Modules messages: 363477 nosy: auscompgeek priority: normal severity: normal status: open title: math.copysign raises SystemError with non-float x and custom y type: behavior _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39871> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com