Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

TYP: np.ndarray.tolist return type seems broken in numpy 2.2.0 #27944

Copy link
Copy link
Closed
1 / 11 of 1 issue completed
Closed
Copy link
@neutrinoceros

Description

@neutrinoceros
Issue body actions

Describe the issue:

While upgrading CMasher's CI to numpy 2.2.0, I got a new typechecking error that seems spurious to me. No error is raised with numpy 2.1.3

Reproduce the code example:

import numpy as np

def to_rgb(in_) -> tuple[float, float, float]:
    # minimal mock for matplotlib.colors.to_rgb
    return (1. ,2., 3.)

def foo(name: str, data: list[tuple[float, float, float]]) -> None:
    data_arr = np.array(data)

    if data_arr.dtype.kind == "S":
        cm_data = [str(x) for x in data_arr]
        colorlist = [to_rgb(_) for _ in cm_data]
    else:
        data_arr = np.atleast_2d(data_arr)
        colorlist = data_arr.tolist()

Error message:

cmasher.py:15: error: Incompatible types in assignment (expression has type "str | list[str] | list[list[str]] | list[list[list[Any]]]", variable has type "list[tuple[float, float, float]]")  [assignment]
Found 1 error in 1 file (checked 1 source file)

Python and NumPy Versions:

2.2.0
3.13.1 (main, Dec  4 2024, 16:25:14) [Clang 16.0.0 (clang-1600.0.26.4)]

Type-checker version and settings:

mypy==1.13.0

no custom settings

Additional typing packages.

Included with mypy, but not used here (as far as I'm aware)

typing-extensions==4.12.2

Sub-issues

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.