Crash Report
On the current numpy main branch (https://github.com/numpy/numpy/tree/87310db7f2a791b4a4e8503d4111359d85052cd4), mypy crashes when a result of np.unique is assigned to a variable named _ (this name matters).
This currently causes mypy_primer to crash when running in optuna, first observed in numpy/numpy#32231 (comment).
Traceback
Traceback (most recent call last):
File "mypy/checker.py", line 765, in accept
File "mypy/nodes.py", line 1909, in accept
File "mypy/checker.py", line 3367, in visit_assignment_stmt
self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None)
File "mypy/checker.py", line 3419, in check_assignment
self.check_assignment_to_multiple_lvalues(
File "mypy/checker.py", line 4182, in check_assignment_to_multiple_lvalues
self.check_multi_assignment(lvalues, rvalue, context, infer_lvalue_type)
File "mypy/checker.py", line 4260, in check_multi_assignment
self.check_multi_assignment_from_tuple(
File "mypy/checker.py", line 4411, in check_multi_assignment_from_tuple
assert isinstance(reinferred_rvalue_type, TupleType)
AssertionError
Repro
Run mypy --no-incremental --show-traceback t.py on
# t.py
import numpy as np
def f(a: np.ndarray) -> None:
_, ranks = np.unique(a, return_inverse=True)
with the latest numpy@main installed (e.g. https://github.com/numpy/numpy/tree/87310db7f2a791b4a4e8503d4111359d85052cd4)
Note that with --allow-redefinition this doesn't crash. It also doesn't crash when renaming _ to something else.
This isn't an issue with the latest 2.5.2 NumPy release, where np.unique counts 32 overloads instead of the current 74 overloads (each of which serve a purpose and are handwritten by me, in case you were wondering).
Your Environment
- Mypy version used: 2.3.0 (compiled: yes), also
2.4.0+dev.5bb72b7
- Mypy command-line flags: see above
- Mypy configuration options from
mypy.ini (and other config files): none
- Python version used: 3.12, 3.14 (doesn't matter)
- Operating system and version: linux, but I don't think this matters
Crash Report
On the current numpy main branch (https://github.com/numpy/numpy/tree/87310db7f2a791b4a4e8503d4111359d85052cd4), mypy crashes when a result of
np.uniqueis assigned to a variable named_(this name matters).This currently causes mypy_primer to crash when running in optuna, first observed in numpy/numpy#32231 (comment).
Traceback
Repro
Run
mypy --no-incremental --show-traceback t.pyonwith the latest numpy@main installed (e.g. https://github.com/numpy/numpy/tree/87310db7f2a791b4a4e8503d4111359d85052cd4)
Note that with
--allow-redefinitionthis doesn't crash. It also doesn't crash when renaming_to something else.This isn't an issue with the latest 2.5.2 NumPy release, where
np.uniquecounts 32 overloads instead of the current 74 overloads (each of which serve a purpose and are handwritten by me, in case you were wondering).Your Environment
2.4.0+dev.5bb72b7mypy.ini(and other config files): none