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
Should throw an error because in some sense the return type of adding the tuple x2 will not be the same type when you add it, as the Addable Protocol would indicate. pyright gives the following error:
Expression of type "tuple[Literal[1], Literal[2]]" cannot be assigned to declared type "Addable"
"tuple[Literal[1], Literal[2]]" is incompatible with protocol "Addable"
"__add__" is an incompatible type
No overloaded function matches type "(other: tuple[Literal[1], Literal[2]], /) -> tuple[Literal[1], Literal[2]]"
Type "(__x: tuple[Literal[1, 2], ...], /) -> tuple[Literal[1, 2], ...]" cannot be assigned to type "(other: tuple[Literal[1], Literal[2]], /) -> tuple[Literal[1], Literal[2]]"
Function return type "tuple[Literal[1, 2], ...]" is incompatible with type "tuple[Literal[1], Literal[2]]"
Type "(__x: tuple[_T@__add__, ...], /) -> tuple[_T@__add__ | Literal[1, 2], ...]" cannot be assigned to type "(other: tuple[Literal[1], Literal[2]], /) -> tuple[Literal[1], Literal[2]]"
Function return type "tuple[Literal[1, 2], ...]" is incompatible with type "tuple[Literal[1],
I don't think this is incorrect; it just depends on how the type of these tuple is inferred. Pyright infers the type as tuple[Literal[1], Literal[2]], which is valid, but another valid type for these tuples is tuple[int, ...], which does indeed follow the Addable protocol.
I don't think this is incorrect; it just depends on how the type of these tuple is inferred. Pyright infers the type as tuple[Literal[1], Literal[2]], which is valid, but another valid type for these tuples is tuple[int, ...], which does indeed follow the Addable protocol.
Yup, I'm better understanding the design choices here of the different type checkers. Thanks for your time replying.
Bug Report
In attempting to create an "Addable Protocol" I messed up and it does not work for Tuples, but mypy does not give me an error where as pyright does.
To Reproduce
Create the Python file:
And run mypy --strict on this file.
Expected Behavior
Should throw an error because in some sense the return type of adding the tuple
x2
will not be the same type when you add it, as theAddable
Protocol would indicate. pyright gives the following error:One of the pyright maintainers kindly gave a detailed explanation here: microsoft/pyright#4613 (comment)
Actual Behavior
mypy outputs that everything is fine:
Your Environment
mypy.ini
(and other config files): N/AThe text was updated successfully, but these errors were encountered: