8000 [Bug]: `LinearSegmentedColormap.from_list` does not have all type hints for argument `colors` · Issue #28067 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
[Bug]: LinearSegmentedColormap.from_list does not have all type hints for argument colors #28067
Closed
@FelipeCybis

Description

@FelipeCybis

Bug summary

Today only ArrayLike is used but it can also be a list or a tuple of 2-element tuples containing (value, color-like), as stated in the docs "If only colors are given, they are equidistantly mapped from the range [0, 1]; i.e. 0 maps to colors[0] and 1 maps to colors[-1]. If (value, color) pairs are given, the mapping is from value to color. This can be used to divide the range unevenly."

Code for reproduction

Create a test.py

from matplotlib.colors import LinearSegmentedColormap

colors = [(0.0, (0.0, 0.0, 0.0, 0.0)), (1.0, (1.0, 1.0, 1.0, 1.0))]
LinearSegmentedColormap.from_list(name="mycmap", colors=colors)

LinearSegmentedColormap.from_list(name="mycmap", colors=tuple(colors))

test with mypy: mypy test.py

Actual outcome

test.py:4: error: Argument "colors" to "from_list" of "LinearSegmentedColormap" has incompatible type "list[tuple[float, tuple[float, float, float, float]]]"; expected "_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]"  [arg-type]
test.py:6: error: Argument "colors" to "from_list" of "LinearSegmentedColormap" has incompatible type "tuple[tuple[float, tuple[float, float, float, float]], ...]"; expected "_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]"  [arg-type]
Found 2 errors in 1 files (checked 1 source file)

Expected outcome

Expected no errors since this is possible and documented.

Success: no issues found in 1 source file

Additional information

No response

Operating system

No response

Matplotlib Version

3.8.3

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0