-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[red-knot] A FunctionType can be a subtype of Callable (but never the other way around)
#16970
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] A FunctionType can be a subtype of Callable (but never the other way around)
#16970
Conversation
|
|
Ive just added the test that is failing, I'm not sure why it is failing though, any help is appreciated. |
|
Maybe an interesting point, and a question i have, should: is_subtype_of(CallableTypeFromFunction[f], CallableTypeFromFunction[g]))
=>
is_subtype_of(TypeOf[f], TypeOf[g])I guess this just depends on how we define FunctionLiteral arms in is_subtype_of. I would think that this equality should hold, but interested to see if there are any points against this |
carljm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Barring the one test that should be changed, this looks good to me, and reasonably well tested!
|
|
||
| static_assert(not is_subtype_of(TypeOf[optional_return_type], TypeOf[required_return_type])) | ||
| static_assert(is_subtype_of(TypeOf[required_return_type], TypeOf[optional_return_type])) | ||
| static_assert(is_subtype_of(TypeOf[optional_return_type], Callable[[], int | None])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For good measure, we could assert this is not true the other way around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant both, but after reviewing the rest of the PR I think this is already adequately tested.
crates/red_knot_python_semantic/resources/mdtest/type_properties/is_subtype_of.md
Outdated
Show resolved
Hide resolved
No, this should not hold, for the same reason mentioned in my review above. |
Okay sounds good, thank you for the response and review. I think i thought |
…es/is_subtype_of.md Co-authored-by: Carl Meyer <carl@oddbird.net>
Summary
Partially fixes #16953
Test Plan
Update is_subtype_of.md
Im unsure how thoroughly this needs to be tested, im not sure if it does for many more function types?