Skip to content

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

Closed

Description

@JelleZijlstra

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.

Activity

  1. JelleZijlstra commented on May 24, 2023

    @JelleZijlstra
    MemberAuthor

    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.

  2. AlexWaygood commented on May 24, 2023

    @AlexWaygood
    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

  3. jorenham commented on Mar 5, 2025

    @jorenham
    Contributor

    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)
  4. added a commit that references this issue on Mar 5, 2025
    754596c
  5. added a commit that references this issue on Mar 7, 2025
    a067d84
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions