Content-Length: 291322 | pFad | https://github.com/python/cpython/issues/101410

92 Customize and improve error messages in the math module. · Issue #101410 · python/cpython · GitHub
Skip to content

Customize and improve error messages in the math module. #101410

@rhettinger

Description

@rhettinger

The default error messages on a several math functions are mostly opaque and and unhelpful.

>>> sqrt(-5)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: math domain error

It would require some effort, but the code could be refactored to give a customized and helpful response, a least in common cases (falling back to the C error code message when the cause is not known):

ValueError:  math.sqrt() expects a non-negative input.  See cmath.sqrt() for variation that supports complex numbers
ValueError:  math.log() requires a non-negative input.   

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/python/cpython/issues/101410

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy