Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math.copysign raises SystemError with non-float x and custom y #84052

Closed
auscompgeek mannequin opened this issue Mar 6, 2020 · 13 comments
Closed

math.copysign raises SystemError with non-float x and custom y #84052

auscompgeek mannequin opened this issue Mar 6, 2020 · 13 comments
Assignees
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes easy extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@auscompgeek
Copy link
Mannequin

auscompgeek mannequin commented Mar 6, 2020

BPO 39871
Nosy @mdickinson, @methane, @auscompgeek, @ZackerySpytz, @miss-islington
PRs
  • bpo-39871: Fix possible SystemErrors in math.{atan2,copysign,remainder}() #18806
  • [3.8] bpo-39871: Fix possible SystemError in atan2, copysign and remainder (GH-18806) #18989
  • [3.7] bpo-39871: Fix possible SystemError in atan2, copysign and remainder (GH-18806) #18990
  • bpo-39871: Fix an error in a news entry #21749
  • [3.9] bpo-39871: Fix an error in a news entry (GH-21749) #21760
  • [3.8] bpo-39871: Fix an error in a news entry (GH-21749) #22333
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/mdickinson'
    closed_at = <Date 2020-03-14.11:53:04.104>
    created_at = <Date 2020-03-06.02:59:01.549>
    labels = ['easy', 'type-bug', '3.8', '3.9', 'extension-modules', '3.7']
    title = 'math.copysign raises SystemError with non-float x and custom y'
    updated_at = <Date 2020-10-26.05:37:20.036>
    user = 'https://github.com/auscompgeek'

    bugs.python.org fields:

    activity = <Date 2020-10-26.05:37:20.036>
    actor = 'methane'
    assignee = 'mark.dickinson'
    closed = True
    closed_date = <Date 2020-03-14.11:53:04.104>
    closer = 'mark.dickinson'
    components = ['Extension Modules']
    creation = <Date 2020-03-06.02:59:01.549>
    creator = 'auscompgeek'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39871
    keywords = ['patch', 'easy (C)']
    message_count = 13.0
    messages = ['363477', '363492', '363493', '363495', '363496', '363505', '364150', '364152', '364154', '364155', '374975', '374976', '379640']
    nosy_count = 5.0
    nosy_names = ['mark.dickinson', 'methane', 'auscompgeek', 'ZackerySpytz', 'miss-islington']
    pr_nums = ['18806', '18989', '18990', '21749', '21760', '22333']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue39871'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    @auscompgeek
    Copy link
    Mannequin Author

    auscompgeek mannequin commented Mar 6, 2020

    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

    @auscompgeek auscompgeek mannequin added extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error labels Mar 6, 2020
    @serhiy-storchaka serhiy-storchaka added easy 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes labels Mar 6, 2020
    @mdickinson
    Copy link
    Member

    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".)

    @mdickinson
    Copy link
    Member

    @david: do you have any interest in creating a PR?

    @auscompgeek
    Copy link
    Mannequin Author

    auscompgeek mannequin commented Mar 6, 2020

    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.

    @mdickinson
    Copy link
    Member

    No problem; I'll likely pick it up (if no-one else does) in the next few days.

    @mdickinson mdickinson self-assigned this Mar 6, 2020
    @ZackerySpytz
    Copy link
    Mannequin

    ZackerySpytz mannequin commented Mar 6, 2020

    I have created a pull request to fix this issue. Please consider taking a look.

    @mdickinson
    Copy link
    Member

    New changeset 5208b4b by Zackery Spytz in branch 'master':
    bpo-39871: Fix possible SystemError in atan2, copysign and remainder (GH-18806)
    5208b4b

    @mdickinson
    Copy link
    Member

    New changeset e634a8a by Mark Dickinson in branch '3.8':
    [3.8] bpo-39871: Fix possible SystemError in atan2, copysign and remainder (GH-18806) (GH-18989)
    e634a8a

    @mdickinson
    Copy link
    Member

    New changeset 4dcfe5f by Mark Dickinson in branch '3.7':
    [3.7] bpo-39871: Fix possible SystemError in atan2, copysign and remainder (GH-18806) (GH-18990)
    4dcfe5f

    @mdickinson
    Copy link
    Member

    Zackery: Thanks for the fix! Now merged and backported to 3.8 and 3.7.

    @methane
    Copy link
    Member

    methane commented Aug 7, 2020

    New changeset 5463635 by Zackery Spytz in branch 'master':
    bpo-39871: Fix an error in a news entry (GH-21749)
    5463635

    @miss-islington
    Copy link
    Contributor

    New changeset fc354ca by Miss Islington (bot) in branch '3.9':
    bpo-39871: Fix an error in a news entry (GH-21749)
    fc354ca

    @methane
    Copy link
    Member

    methane commented Oct 26, 2020

    New changeset f6255a2 by Zackery Spytz in branch '3.8':
    bpo-39871: Fix an error in a news entry (GH-21749)
    f6255a2

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes easy extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants