Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TYP: regression between 2.1.3 and 2.2.0 (mypy only) #27957

Closed
@stefanv

Description

@stefanv

Describe the issue:

The following code seems correct, and passes type checking under 2.1.3 but not 2.2.0:

import numpy as np

rng = np.random.default_rng(27446968)
n_states = 5

P = rng.random(size=(n_states, n_states))
p = rng.random(n_states)

p = P.T @ p

I suppose mypy is flagging that the float width can increase, but since float64 is used by random, that won't happen in this scenario.

Reproduce the code example:

N/A

Error message:

foo.py:10: error: Incompatible types in assignment (expression has type "ndarray[tuple[int, ...], dtype[floating[Any]]]", variable has type "ndarray[tuple[int, ...], dtype[float64]]")  [assignment]
Found 1 error in 1 file (checked 1 source file)

Python and NumPy Versions:

Python 3.13, mypy 1.13, numpy 2.2.0

Runtime Environment:

No response

Context for the issue:

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions