-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
status: deferredIssue or PR deferred until some precondition is fixedIssue or PR deferred until some precondition is fixedstubs: false positiveType checkers report false errorsType checkers report false errors
Description
Given the following code snippet:
buf = b"abcdefg"
view = memoryview(buf).cast("c")
for c in view:
print(type(c))
if c == b"c":
print("Found c")Inside the loop, the variable c is always type bytes. However, mypy believes it to be int and reports an error:
$ mypy --version
mypy 0.961 (compiled: yes)
$ mypy --strict ~/test.py
/home/jon/test.py:5: error: Non-overlapping equality check (left operand type: "int", right operand type: "Literal[b'c']")
Found 1 error in 1 file (checked 1 source file)
Running the script confirms the type is bytes:
$ python ~/test.py
<class 'bytes'>
<class 'bytes'>
<class 'bytes'>
Found c
<class 'bytes'>
<class 'bytes'>
<class 'bytes'>
<class 'bytes'>
Docs on this method:
https://docs.python.org/3/library/stdtypes.html#memoryview.cast
Metadata
Metadata
Assignees
Labels
status: deferredIssue or PR deferred until some precondition is fixedIssue or PR deferred until some precondition is fixedstubs: false positiveType checkers report false errorsType checkers report false errors