Ignore doesn't work when two errors share a line · Issue #17655 · python/mypy (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

@NeilGirdhar

Description

@NeilGirdhar

from typing import Any

from array_api_compat import get_namespace import numpy as np import numpy.typing as npt

def create_diagonal_array(m: npt.NDArray[Any]) -> npt.NDArray[Any]: """A vectorized version of diagonal.

Args:
    m: Has shape (*k, n)
Returns: Array with shape (*k, n, n) and the elements of m on the diagonals.
"""
xp = get_namespace(m)
pre = m.shape[:-1]
n = m.shape[-1]
s = (*m.shape, n)
retval = xp.zeros((*pre, n ** 2), dtype=m.dtype)
for index in np.ndindex(*pre):
    target_index = (*index, slice(None, None, n + 1))
    source_values = m[*index, :]  # type: ignore[arg-type]
    retval[target_index] = source_values
return xp.reshape(retval, s)

Produces an error without a line number for a line on which the error should be ignored!