Skip to content

Failed doctest test for decimal.Decimal.__round__ #109861

Description

@serhiy-storchaka

Bug report

Bug description:

$ ./python -m test -v test_decimal -m __round__
...
======================================================================
FAIL: __round__ (decimal.Decimal)
Doctest: decimal.Decimal.__round__
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/serhiy/py/cpython/Lib/doctest.py", line 2250, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for decimal.Decimal.__round__
  File "/home/serhiy/py/cpython/Lib/decimal.py", line unknown line number, in __round__

----------------------------------------------------------------------
File "/home/serhiy/py/cpython/Lib/decimal.py", line ?, in decimal.Decimal.__round__
Failed example:
    round(Decimal('-Infinity'), 37)
Exception raised:
    Traceback (most recent call last):
      File "/home/serhiy/py/cpython/Lib/doctest.py", line 1374, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest decimal.Decimal.__round__[10]>", line 1, in <module>
        round(Decimal('-Infinity'), 37)
      File "/home/serhiy/py/cpython/Lib/_pydecimal.py", line 1892, in __round__
        return self.quantize(exp)
               ^^^^^^^^^^^^^^^^^^
      File "/home/serhiy/py/cpython/Lib/_pydecimal.py", line 2566, in quantize
        return context._raise_error(InvalidOperation,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/serhiy/py/cpython/Lib/_pydecimal.py", line 4058, in _raise_error
        raise error(explanation)
    decimal.InvalidOperation: quantize with one INF
----------------------------------------------------------------------
File "/home/serhiy/py/cpython/Lib/decimal.py", line ?, in decimal.Decimal.__round__
Failed example:
    round(Decimal('sNaN123'), 0)
Exception raised:
    Traceback (most recent call last):
      File "/home/serhiy/py/cpython/Lib/doctest.py", line 1374, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest decimal.Decimal.__round__[11]>", line 1, in <module>
        round(Decimal('sNaN123'), 0)
      File "/home/serhiy/py/cpython/Lib/_pydecimal.py", line 1892, in __round__
        return self.quantize(exp)
               ^^^^^^^^^^^^^^^^^^
      File "/home/serhiy/py/cpython/Lib/_pydecimal.py", line 2559, in quantize
        ans = self._check_nans(exp, context)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/serhiy/py/cpython/Lib/_pydecimal.py", line 776, in _check_nans
        return context._raise_error(InvalidOperation, 'sNaN',
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/serhiy/py/cpython/Lib/_pydecimal.py", line 4058, in _raise_error
        raise error(explanation)
    decimal.InvalidOperation: sNaN


----------------------------------------------------------------------

CPython versions tested on:

3.11, 3.12, CPython main branch

Operating systems tested on:

No response

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixestestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions