8000 TYP: array.tolist() returns a list of strings · Issue #28240 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

TYP: array.tolist() returns a list of strings #28240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
b-kamphorst opened this issue Jan 28, 2025 · 1 comment
Closed

TYP: array.tolist() returns a list of strings #28240

b-kamphorst opened this issue Jan 28, 2025 · 1 comment

Comments

@b-kamphorst
Copy link

Describe the issue:

Mypy believes that the array.tolist() method returns (a nested) list of strings, even if the array is filled with other objects such as integers.

Reproduce the code example:

import numpy as np


def main() -> None:
    arr = np.array([1, 2])
    arr2: list[int] = arr.tolist()

Error message:

test.py: note: In function "main":
test.py:7: error: Incompatible types in assignment (expression has type "str | list[str] | list[list[str]] | list[list[list[Any]]]", variable has type "list[int]")  [assignment]

Python and NumPy Versions:

numpy: 2.2.2
Python: 3.12.2 (main, Oct 17 2024, 10:53:28) [GCC 11.4.0]

Type-checker version and settings:

mypy 1.11.2 (compiled: yes)

Additional typing packages.

No response

@jorenham
Copy link
Member

duplicate of #27944

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
0