Skip to content

colorsys module outputs out of bound values #148979

@manoj-km24

Description

@manoj-km24

Bug report

Bug description:

In the colorsys.py module, the conversion functions output values out of range if the given input is invalid. Example:

>>> import colorsys
>>> colorsys.rgb_to_hls(10,20,30)
(0.5833333333333334, 20.0, -0.5263157894736842)

In the above example, the output HLS color is invalid since l is in range [0,1]. This is also specified in the colorsys documentation.

This issue has already been discussed at : #102581

I believe it can be solved in many ways such as:

  • Mandatory or optional clipping
  • Raising errors
  • Adding new functions inside the module that make validation mandatory along with the existing functions
  • Modify the conversion functions to accept new arguments such as clip or validate

as discussed in the old issue. Whatever way it is, I am open for discussion and solving it with a PR.

CPython versions tested on:

3.13

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions