Skip to content

Issue with annotation six.byte2int starting 1.16.21.2 #9145

Closed

Description

@levincarmel

Hi,
Starting 1.16.21.2 we have an issue with mypy failing for annotations of six.byte2int.
We had this method:

def byte2int(c: Union[bytes, int]) -> int:
    if isinstance(c, bytes):
        return six.byte2int(c)
    return c

which was called the following way:
pp_fingerprint = ":".join("{:02x}".format(byte2int(c)) for c in fingerprint).upper()

This used to work until now, but now we get this failure:
Argument 1 to "byte2int" has incompatible type "bytes"; expected "SupportsGetItem[int, <nothing>]"
Is this an issue with this release? Or are we supposed to fix our annotations in some way?

Thanks in advance!

Activity

  1. AlexWaygood commented on Nov 10, 2022

    @AlexWaygood
    Member
  2. Avasam commented on Nov 10, 2022

    @Avasam
    SponsorCollaborator

    The example can be simplified to:

    import six
    six.byte2int(b"1")
    

    Weird mypy-specific issue that I ironically didn't catch because I was specifically trying to not use bytes.
    An overload easily fixes this, PR incoming.

    Ref python/mypy#14032 because I don't know if it's the same issue we were having with itemgetter.

    Update: Seems to be caused by outdated typeshed stub. This can be discussed in the PR below.

  3. JelleZijlstra commented on Nov 10, 2022

    @JelleZijlstra
    Member

    @levincarmel what version of mypy are you running?

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions