Skip to content

Ignore doesn't work when two errors share a line #17655

Closed
@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!

Metadata

Metadata

Assignees

Labels

bugmypy got something wrong

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions