Skip to content

pyrefly report sometimes does not count annotated attributes as typed in numpy #3400

@jorenham

Description

@jorenham

When I run pyrefly report --public-only --prefer-stubs=true numpy on the numpy 2.4.x branch, then for the following stubs definition (src):

class AxisError(ValueError, IndexError):
    __slots__ = "_msg", "axis", "ndim"

    axis: int | None
    ndim: int | None
    @overload
    def __init__(self, axis: str, ndim: None = None, msg_prefix: None = None) -> None: ...
    @overload
    def __init__(self, axis: int, ndim: int, msg_prefix: str | None = None) -> None: ...

it reports

        {
          "kind": "attr",
          "name": "numpy.exceptions.AxisError.axis",
          "n_typable": 1,
          "n_typed": 0,
          "n_any": 0,
          "n_untyped": 1,
          "location": {
            "line": 179,
            "column": 18
          }
        },
        {
          "kind": "attr",
          "name": "numpy.exceptions.AxisError.ndim",
          "n_typable": 1,
          "n_typed": 0,
          "n_any": 0,
          "n_untyped": 1,
          "location": {
            "line": 180,
            "column": 18
          }
        },
        {
          "kind": "function",
          "name": "numpy.exceptions.AxisError.__init__",
          "n_typable": 4,
          "n_typed": 4,
          "n_any": 0,
          "n_untyped": 0,
          "location": {
            "line": 24,
            "column": 5
          }
        },
        {
          "kind": "function",
          "name": "numpy.exceptions.AxisError.__str__",
          "n_typable": 0,
          "n_typed": 0,
          "n_any": 0,
          "n_untyped": 0,
          "location": {
            "line": 186,
            "column": 5
          }
        },
        {
          "kind": "class",
          "name": "numpy.exceptions.AxisError",
          "n_typable": 0,
          "n_typed": 0,
          "n_any": 0,
          "n_untyped": 0,
          "location": {
            "line": 19,
            "column": 1
          }
        },

Even though, clearly, the axis and ndim are fully typed.

It's also kinda strange that __str__ is reported here, btw.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions