This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: math.copysign raises SystemError with non-float x and custom y
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: mark.dickinson Nosy List: ZackerySpytz, auscompgeek, mark.dickinson, methane, miss-islington
Priority: normal Keywords: easy (C), patch

Created on 2020-03-06 02:59 by auscompgeek, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 18806 closed ZackerySpytz, 2020-03-06 13:16
PR 18989 merged mark.dickinson, 2020-03-14 11:05
PR 18990 merged mark.dickinson, 2020-03-14 11:30
PR 21749 merged ZackerySpytz, 2020-08-06 05:53
PR 21760 merged miss-islington, 2020-08-07 05:39
PR 22333 merged ZackerySpytz, 2020-09-21 05:30
Messages (13)
msg363477 - (view) Author: David Vo (auscompgeek) Date: 2020-03-06 02:59
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
msg363492 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2020-03-06 07:48
Nice find. This affects not just copysign, but all of the math module functions that use FUNC2 under the hood. (I think that's just "remainder", "atan2" and "copysign".)
msg363493 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2020-03-06 07:49
@David: do you have any interest in creating a PR?
msg363495 - (view) Author: David Vo (auscompgeek) Date: 2020-03-06 08:24
I'm currently rather busy with other work, but if this happens to still be open in a couple of months I might pick it up.
msg363496 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2020-03-06 08:26
No problem; I'll likely pick it up (if no-one else does) in the next few days.
msg363505 - (view) Author: Zackery Spytz (ZackerySpytz) * (Python triager) Date: 2020-03-06 13:18
I have created a pull request to fix this issue.  Please consider taking a look.
msg364150 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2020-03-14 10:45
New changeset 5208b4b37953a406db0ed6a9db545c2948dde989 by Zackery Spytz in branch 'master':
bpo-39871: Fix possible SystemError in atan2, copysign and remainder (GH-18806)
https://github.com/python/cpython/commit/5208b4b37953a406db0ed6a9db545c2948dde989
msg364152 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2020-03-14 11:38
New changeset e634a8ac1f8a2904a2241b83fc5e4c9f40d5c7ca by Mark Dickinson in branch '3.8':
[3.8] bpo-39871: Fix possible SystemError in atan2, copysign and remainder (GH-18806) (GH-18989)
https://github.com/python/cpython/commit/e634a8ac1f8a2904a2241b83fc5e4c9f40d5c7ca
msg364154 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2020-03-14 11:51
New changeset 4dcfe5f2e4bad8e03990de75d8d4ec20e8aa23b3 by Mark Dickinson in branch '3.7':
[3.7] bpo-39871: Fix possible SystemError in atan2, copysign and remainder (GH-18806) (GH-18990)
https://github.com/python/cpython/commit/4dcfe5f2e4bad8e03990de75d8d4ec20e8aa23b3
msg364155 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2020-03-14 11:53
Zackery: Thanks for the fix! Now merged and backported to 3.8 and 3.7.
msg374975 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2020-08-07 05:38
New changeset 54636355805dd2877bb54fbad8d967e1ddd8b553 by Zackery Spytz in branch 'master':
bpo-39871: Fix an error in a news entry (GH-21749)
https://github.com/python/cpython/commit/54636355805dd2877bb54fbad8d967e1ddd8b553
msg374976 - (view) Author: miss-islington (miss-islington) Date: 2020-08-07 05:45
New changeset fc354ca51d0b6f24f2871788dfa7e35c56129f8b by Miss Islington (bot) in branch '3.9':
bpo-39871: Fix an error in a news entry (GH-21749)
https://github.com/python/cpython/commit/fc354ca51d0b6f24f2871788dfa7e35c56129f8b
msg379640 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2020-10-26 05:37
New changeset f6255a2ccb55a63194caf698f471c803c08be359 by Zackery Spytz in branch '3.8':
bpo-39871: Fix an error in a news entry (GH-21749)
https://github.com/python/cpython/commit/f6255a2ccb55a63194caf698f471c803c08be359
History
Date User Action Args
2022-04-11 14:59:27adminsetgithub: 84052
2020-10-26 05:37:20methanesetmessages: + msg379640
2020-09-21 05:30:57ZackerySpytzsetpull_requests: + pull_request21378
2020-08-07 05:45:56miss-islingtonsetmessages: + msg374976
2020-08-07 05:39:12miss-islingtonsetnosy: + miss-islington

pull_requests: + pull_request20905
2020-08-07 05:38:52methanesetnosy: + methane
messages: + msg374975
2020-08-06 05:53:43ZackerySpytzsetpull_requests: + pull_request20893
2020-03-14 11:53:04mark.dickinsonsetstatus: open -> closed
resolution: fixed
messages: + msg364155

stage: patch review -> resolved
2020-03-14 11:51:56mark.dickinsonsetmessages: + msg364154
2020-03-14 11:38:55mark.dickinsonsetmessages: + msg364152
2020-03-14 11:30:41mark.dickinsonsetpull_requests: + pull_request18337
2020-03-14 11:05:47mark.dickinsonsetpull_requests: + pull_request18336
2020-03-14 10:45:40mark.dickinsonsetmessages: + msg364150
2020-03-06 13:18:16ZackerySpytzsetmessages: + msg363505
2020-03-06 13:16:39ZackerySpytzsetkeywords: + patch
nosy: + ZackerySpytz

pull_requests: + pull_request18164
stage: needs patch -> patch review
2020-03-06 08:26:26mark.dickinsonsetassignee: mark.dickinson
messages: + msg363496
2020-03-06 08:24:12auscompgeeksetmessages: + msg363495
2020-03-06 07:49:46mark.dickinsonsetmessages: + msg363493
2020-03-06 07:48:46mark.dickinsonsetmessages: + msg363492
2020-03-06 07:44:55mark.dickinsonsetnosy: + mark.dickinson
2020-03-06 06:48:12serhiy.storchakasetkeywords: + easy (C)
stage: needs patch
versions: + Python 3.7, Python 3.8, Python 3.9
2020-03-06 02:59:01auscompgeekcreate