-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[red-knot] add support for typing.cast #15379
Comments
I'm working on this. It turned out not to be so simple, due to how cast(str, True) let Some((casted_ty, _)) = binding.two_parameter_tys() else { /* ... */ };
// ^^^^^^^^^ str | Literal[True] A possible reason is that @overload
def cast(typ: type[_T], val: Any) -> _T: ...
@overload
def cast(typ: str, val: Any) -> Any: ...
@overload
def cast(typ: object, val: Any) -> Any: ... |
Open question: Should there be a "strict casting" mode in which a value cannot be casted to a type with which its own inferred type does not overlap (or of which it is not a supertype/subtype)? Basedpyright calls this |
Oh! Yeah, this is because we don't understand overloads, so we treat it as a function defined with an unknown decorator, meaning we currently replace its signature with the "todo signature" Short of supporting overloads, which will be a somewhat bigger feature (though we should do it soon), I think the easiest workaround here is to change our definition of the todo signature to |
I wouldn't add that now. We can certainly consider it as a feature later, but it's not a "table stakes" feature that we need in order to be usable. It's an opinionated extension of the way |
basedmypy also reports errors with non-overlapping casts |
This should be pretty simple to add, once support for
assert_type
(and functions that take some value expressions and some type expressions) lands.The text was updated successfully, but these errors were encountered: