-
Notifications
You must be signed in to change notification settings - Fork 3
Update tests #572
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
Update tests #572
Conversation
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesCodacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more |
|
Sorry, I didn't manage to get to this today. Should get it tomorrow. |
liamhuber
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.
Ok, if you read my commit suggestion and it makes sense and passes the tests, then I've understood this well enough that I've reviewed it and it's approved by me.
But, if you look at that suggestion and you wonder what the heck I was thinking, then either you need to hold my hand or I need to check out the branch and try stuff out, because I've misunderstood. In that case my approval is worth what I've understood -- nothing 😝
|
|
||
| def test_get_type_hints(self): | ||
| for hint, origin in [ | ||
| (int | float, type(int| float)), |
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.
Is it really intentional to do type(int | float) and not type[int | float] here?
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.
What does type[int | float] mean?
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.
It is a type hint, that we expect the type int or the type float. In this case bool also works, since it's a subclass of int, but, e.g. string doesn't.
The int | float is generating a typing union, and we're treating type as a generic (i.e. takes subtyoes like list[], so what we've written is shorthand for x: type[int] | type[float].
Concretely, the following runs and mypyp will complain only about foo(str):
def foo(x: type[int, float]) -> None:
print(x)
foo(int) # Fine -- in the type hint
foo(bool) # Fine -- subclass of int
foo(str) # mypy complains
def equivalent_to_foo(x: type[int] | type[float]) -> None:
print(x)type(int | float) is an instance of types.UnionType. Looking at it again, I guess this is actually exactly what you want, since the hint int | float should indeed have a UnionType origin. It's not clear to me whether it matters that you put int | float inside the union type, as I don't know how detailed its == comparison is.
Co-authored-by: Liam Huber <liamhuber@greyhavensolutions.com>
liamhuber
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.
Nice, looks like I understood ok. LGTM.
I updated the type checking because otherwise it fails with annotated typing