You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ mypy test.py
1.py:10:17: note: Revealed type is "builtins.str"
1.py:11:47: error: Argument "byteorder" to "from_bytes" of "int" has incompatible type "str"; expected "Union[Literal['little'], Literal['big']]"
With mypy-0.920 and later. 0.910 correctly inferred byteorder as Literal['little'] | Literal['big']
The text was updated successfully, but these errors were encountered:
I don't think mypy ever inferred the type of byteorder as Literal['little', 'big']. I think we always inferred str but 0.920 changed the type signature of int.from_bytes to take a Literal instead of a str, turning this into an error. (That change was added in python/typeshed#5715 and added to mypy in #10862, which was included in 0.920).
You can silence the error by adding an explicit Literal["little", "big"] type for byteorder.
@pranavrajpal, you're right, 0.910 also doesn't infer byteorder as Literal. I somehow convinced myself that it did. Not an inference regression then. Thanks for the explanation!
test.py
:Results in
With mypy-0.920 and later. 0.910 correctly inferred
byteorder
asLiteral['little'] | Literal['big']
The text was updated successfully, but these errors were encountered: