[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.
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.
For good measure, we could assert this is not true the other way around.
There was a problem hiding this comment.
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 <[email protected]>
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?