Skip to content

Properly address new stubtest errors from mypy v1.18.1 #14718

Closed

Description

@brianschubert

#14699 added several allowlist entries that need to be investigated more closely. These are marked with the comment # FIXME: new stubtest errors from mypy v1.18.1, and are repeated below.

Any help is appreciated!

The new allowlist entries:

Activity

  1. added
    stubs: improvementImprove/refactor existing annotations, other stubs issues
    help wantedAn actionable problem of low to medium complexity where a PR would be very welcome
    on Sep 14, 2025
  2. JanEricNitschke commented on Sep 14, 2025

    @JanEricNitschke
    Contributor

    Id love to have a look as a first (proper) contribution. Do you have some documentation about what tests/checks to run?

    The contributing guide is a bit lacking there i feel.

  3. brianschubert commented on Sep 14, 2025

    @brianschubert
    CollaboratorAuthor
  4. JanEricNitschke commented on Sep 15, 2025

    @JanEricNitschke
    Contributor

    For the openpyxl one we have:

    Runtime

    class Sequence(Descriptor):
        expected_type = type(None)
        seq_types = (list, tuple)
        idx_base = 0
        unique = False
        container = list
    
    class UniqueSequence(Sequence):
        """
        Use a set to keep values unique
        """
        seq_types = (list, tuple, set)
        container = set

    Stubs:

    class Sequence(Descriptor[_ContainerT]):
        expected_type: type[Any]  # expected type of the sequence elements
        seq_types: tuple[type, ...]  # allowed settable sequence types, defaults to `list`, `tuple`
        idx_base: int
        unique: bool
        container: type  # internal container type, defaults to `list`
    
    # `_T` is the type of the elements in the sequence.
    class UniqueSequence(Sequence[set[_T]]):
        seq_types: tuple[type[list[_T]], type[tuple[_T, ...]], type[set[_T]]]
        container: type[set[_T]]
    
    

    and error:

    error: openpyxl.descriptors.sequence.UniqueSequence.seq_types variable differs from runtime type tuple[Overload(def [_T] () -> builtins.list[_T`1], def [_T] (typing.Iterable[_T`1]) -> builtins.list[_T`1]), def [_T_co] (typing.Iterable[_T_co`1] =) -> builtins.tuple[_T_co`1, ...], Overload(def [_T] () -> builtins.set[_T`1], def [_T] (typing.Iterable[_T`1]) -> builtins.set[_T`1])]
    Stub: in file D:\Programming\Projects\typeshed\stubs\openpyxl\openpyxl\descriptors\sequence.pyi:41
    tuple[type[builtins.list[_T`1]], type[builtins.tuple[_T`1, ...]], type[builtins.set[_T`1]]]
    Runtime:
    (<class 'list'>, <class 'tuple'>, <class 'set'>)
    
    
    

    Fix would be

    class UniqueSequence(Sequence[set[_T]]):
        seq_types: tuple[type, ...] # defaults to `list`, `tuple`, `set`
        container: type[set[_T]]
    
    

    i guess. Feels worse, but i guess it matches whats already there for Sequence?

  5. JanEricNitschke commented on Sep 15, 2025

    @JanEricNitschke
    Contributor

    For serial.win32.ULONG_PTR

    we have as the actual code:

    # ULONG_PTR is a an ordinary number, not a pointer and contrary to the name it
    # is either 32 or 64 bits, depending on the type of windows...
    # so test if this a 32 bit windows...
    if is_64bit():
        ULONG_PTR = c_int64
    else:
        ULONG_PTR = c_ulong
    
    
    

    As the stub:

    ULONG_PTR: type[c_int64 | c_ulong]
    

    And from the tesrt

    Stub: in file D:\Programming\Projects\typeshed\stubs\pyserial\serial\win32.pyi:10
    type[ctypes.c_int64] | type[ctypes.c_ulong]
    Runtime: in file C:\Users\Jan-Eric\AppData\Roaming\uv\python\cpython-3.13.1-windows-x86_64-none\Lib\ctypes\__init__.py:213
    <class 'ctypes.c_longlong'>
    
    
    

    So i dont really know if/how to address this. Current situation seems correct to me.

  6. JelleZijlstra commented on Sep 15, 2025

    @JelleZijlstra
    Member

    Yes, the serial.win32 one sounds like something where we should continue to ignore the stubtest error. We should add a comment explaining this to the allowlist though.

    The openpyxl one looks like a bug in stubtest to me; the stub is correct and precise. Probably worth opening an issue on mypy with a minimal example. I haven't tried but probably something like (list,) at runtime vs. tuple[type[list[T]] in the stub is enough.

  7. srittau commented on Sep 16, 2025

    @srittau
    Collaborator

    @brianschubert I've converted the list in your post to a checklist and added links to the relevant PRs (if any). Hope that's okay.

  8. removed
    help wantedAn actionable problem of low to medium complexity where a PR would be very welcome
    on Sep 19, 2025
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

    stubs: improvementImprove/refactor existing annotations, other stubs issues

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions