Skip to content

BUG: np.allclose pyright reportUnknownMemberType #23137

@FrancescElies

Description

@FrancescElies

Describe the issue:

We are currently evaluating mypy and pyright in our codebase and we found pyright to complain about np.allclose in where maybe it shouldn't.

I am aware that strict mode in mypy and pyright doesn't mean the same, but I wondered where this unknown (see error below) was coming from, in my naive view that script has nothing unknown to it in terms of types, but things are probably more complex under the surface.

I have been suggested that The type dtype is a generic class that accepts a single type argument. Since none is provided, its type is dtype[Unknown]. That's the origin of the Unknown type that pyright is telling you about here. This isn't a bug in pyright. It's an omission in the numpy code, and it would need to be addressed there.

Is this a bug in numpy typing defs?

Reproduce the code example:

# pyright: strict
import numpy as np
np.allclose(np.array([1.0, 2.0, 3.0]), np.array([1.0, 2.0, 3.0]))

Error message:

❯ mypy --strict allclose.py
Success: no issues found in 1 source file
❯ mypy -V
mypy 0.991 (compiled: yes)

But pyright throws the following

❯ pyright allclose.py
No configuration file found.
No pyproject.toml file found.
stubPath C:\s\mytest\numpy\typings is not a valid directory.
Assuming Python platform Windows
Searching for source files
Found 1 source file
pyright 1.1.291
C:\s\mytest\numpy\allclose.py
  C:\s\mytest\numpy\allclose.py:4:1 - error: Type of "allclose" is partially unknown
    Type of "allclose" is "(a: _SupportsArray[dtype[Unknown]] | _NestedSequence[_SupportsArray[dtype[Unknown]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], b: _SupportsArray[dtype[Unknown]] | _NestedSequence[_SupportsArray[dtype[Unknown]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], rtol: float = ..., atol: float = ..., equal_nan: bool = ...) -> bool" (reportUnknownMemberType)
1 error, 0 warnings, 0 informations
Completed in 0.931sec

Runtime information:

In [3]: print(np.show_runtime())
WARNING: `threadpoolctl` not found in system! Install it by `pip install threadpoolctl`. Once installed, try `np.show_runtime` again for more detailed build information
[{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
                      'found': ['SSSE3',
                                'SSE41',
                                'POPCNT',
                                'SSE42',
                                'AVX',
                                'F16C',
                                'FMA3',
                                'AVX2'],
                      'not_found': ['AVX512F',
                                    'AVX512CD',
                                    'AVX512_SKX',
                                    'AVX512_CLX',
                                    'AVX512_CNL',
                                    'AVX512_ICL']}}]

Context for the issue:

For more context see here, also tried asking in the chat too.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions