mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Ignore doesn't work when two errors share a line

Open NeilGirdhar opened this issue 1 year ago • 0 comments

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!

NeilGirdhar avatar Aug 09 '24 17:08 NeilGirdhar