-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Upcasting #1261
Comments
Pyright is doing the right thing here. It's correctly "solving" for the type of TypeVar T, and there are no type violations, so it's not displaying any errors. I might be able to suggest a solution if I better understood what you're trying to do here. A derived class is always compatible with its base class, so there's no need to explicitly upcast. If you want the static type checker to test whether an expression is of a type that is derived from # Will not show an error
y: Base = d
# Will show an error
z: Other = d Does that address your use case? |
I was trying to implement the |
Yeah, there's no need for an |
Describe the bug
Would it be possible to get upcasting using a function to type check its arguments? Or more generally that pyright checks that arguments with
Type
annotation of a generic type e.gType[T]
are compatible with other arguments where the generic typeT
is also used.To Reproduce
Would it be possible to get pyright to type check the last line and give error? Currently it will not detect that the function
upcast
is given two incompatible arguments. Here is how it looks in vscode today:Currently no error will show even if Other is not a super type of the type of d:
VS Code extension or command-line
vscode extension: 1.1.94
The text was updated successfully, but these errors were encountered: