Skip to content

stubtest: Recognize __ as indicating positional-only arg at runtime #15302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JelleZijlstra opened this issue May 24, 2023 · 3 comments · Fixed by #18756
Closed

stubtest: Recognize __ as indicating positional-only arg at runtime #15302

JelleZijlstra opened this issue May 24, 2023 · 3 comments · Fixed by #18756
Labels
bug mypy got something wrong topic-stubtest

Comments

@JelleZijlstra
Copy link
Member

I got this error on typing-extensions:

error: typing_extensions.override is inconsistent, stub argument "__arg" should be positional or keyword (remove leading double underscore)
Stub: in file stdlib\typing_extensions.pyi:366
def [_F <: def (*Any, **Any) -> Any] (_F`-1) -> _F`-1
Runtime: in file C:\Users\RUNNER~1\AppData\Local\Temp\tmp769672by\Lib\site-packages\typing_extensions.py:2403
def (__arg: ~_F) -> ~_F

Since typing_extensions.override uses __arg at runtime, I think stubtest should recognize it as positional-only.

@JelleZijlstra JelleZijlstra added bug mypy got something wrong topic-stubtest labels May 24, 2023
@JelleZijlstra
Copy link
Member Author

It also complains that error: typing_extensions.override is inconsistent, stub argument "__arg" differs from runtime argument "__arg", which is a rather enigmatic issue to resolve.

@AlexWaygood
Copy link
Member

It also complains that error: typing_extensions.override is inconsistent, stub argument "__arg" differs from runtime argument "__arg", which is a rather enigmatic issue to resolve.

That second issue is a duplicate of #14560

@jorenham
Copy link
Contributor

jorenham commented Mar 5, 2025

This issue is also affecting NumPy.

At runtime, numpy.testing._private.utils.check_support_sve (also re-exported in numpy.testing) has the following signature:

def check_support_sve(__cache=[]): ...

I tried annotating it in 3 ways; all of them resulted in a stubtest error. This forces us to put it in the allowist.

attempt 1: pos-only cache

def check_support_sve(cache: list[_T_or_bool] = [], /) -> _T: ...
$ uv run tool/stubtest.py
error: numpy.testing._private.utils.check_support_sve is inconsistent, stub argument "cache" differs from runtime argument "__cache"
Stub: in file src/numpy-stubs/testing/_private/utils.pyi:435
def [_T_or_bool = bool] (list[_T_or_bool`-1 = bool] =) -> _T_or_bool`-1 = bool
Runtime: in file .venv/lib/python3.13/site-packages/numpy/testing/_private/utils.py:1413
def (__cache=[])

error: numpy.testing._private.utils.check_support_sve is inconsistent, stub argument "cache" should be positional or keyword (remove "/")
Stub: in file src/numpy-stubs/testing/_private/utils.pyi:435
def [_T_or_bool = bool] (list[_T_or_bool`-1 = bool] =) -> _T_or_bool`-1 = bool
Runtime: in file .venv/lib/python3.13/site-packages/numpy/testing/_private/utils.py:1413
def (__cache=[])

Found 2 errors (checked 324 modules)

attempt 2: pos-only __cache

def check_support_sve(__cache: list[_T_or_bool] = [], /) -> _T_or_bool: ...
$ uv run tool/stubtest.py
error: numpy.testing._private.utils.check_support_sve is inconsistent, stub argument "__cache" differs from runtime argument "__cache"
Stub: in file src/numpy-stubs/testing/_private/utils.pyi:435
def [_T_or_bool = bool] (list[_T_or_bool`-1 = bool] =) -> _T_or_bool`-1 = bool
Runtime: in file .venv/lib/python3.13/site-packages/numpy/testing/_private/utils.py:1413
def (__cache=[])

error: numpy.testing._private.utils.check_support_sve is inconsistent, stub argument "__cache" should be positional or keyword (remove "/")
Stub: in file src/numpy-stubs/testing/_private/utils.pyi:435
def [_T_or_bool = bool] (list[_T_or_bool`-1 = bool] =) -> _T_or_bool`-1 = bool
Runtime: in file .venv/lib/python3.13/site-packages/numpy/testing/_private/utils.py:1413
def (__cache=[])

Found 2 errors (checked 324 modules)

attempt 3: pos-or-kw __cache

def check_support_sve(__cache: list[_T_or_bool] = []) -> _T_or_bool: ...  # noqa: PYI063
$ uv run tool/stubtest.py
error: numpy.testing._private.utils.check_support_sve is inconsistent, stub argument "__cache" differs from runtime argument "__cache"
Stub: in file src/numpy-stubs/testing/_private/utils.pyi:435
def [_T_or_bool = bool] (list[_T_or_bool`-1 = bool] =) -> _T_or_bool`-1 = bool
Runtime: in file .venv/lib/python3.13/site-packages/numpy/testing/_private/utils.py:1413
def (__cache=[])

error: numpy.testing._private.utils.check_support_sve is inconsistent, stub argument "__cache" should be positional or keyword (remove "/")
Stub: in file src/numpy-stubs/testing/_private/utils.pyi:435
def [_T_or_bool = bool] (list[_T_or_bool`-1 = bool] =) -> _T_or_bool`-1 = bool
Runtime: in file .venv/lib/python3.13/site-packages/numpy/testing/_private/utils.py:1413
def (__cache=[])

Found 2 errors (checked 324 modules)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-stubtest
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants