-
Notifications
You must be signed in to change notification settings - Fork 768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type "int" cannot be assigned to type "Comparable" #2346
Comments
The problem is that your protocol class defines a method If def func(x: CT, y: CT) -> bool:
return x.__lt__(other=y) # Crash if `int` is passed If you attempt to assign an x: Comparable = a
You can fix this by doing one of the following. # This uses the "old style" way of specifying a position-only parameter
# by using a double underscore.
@abstractmethod
def __lt__(self: CT, __other: CT) -> bool:
... or # This uses the newer mechanism introduced in PEP 570.
@abstractmethod
def __lt__(self: CT, other: CT, /) -> bool:
... |
Thank you for the quick response! Confirming that adding "/" to the |
Environment data
Expected behaviour
No error.
Actual behaviour
Pylance reports the following errors on the line
func(a, b)
:Logs
Code Snippet / Additional information
The text was updated successfully, but these errors were encountered: