Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
test: implement type hints #906
test: implement type hints #906
Changes from all commits
6511dcb
f2c6cc9
dcaa093
504525f
6e2ec91
82b2649
72b337a
8e0d612
e9bdb6e
efef3ce
56ddd30
6b08c58
629155d
a9e5617
202a1ef
85e9cf6
cfdd42d
d6fd2b9
7c20e5a
dc76dab
f24917c
38d0a91
2ee76a7
1f3e5a4
70e9d93
0a23f95
0b6a448
f24e290
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Doing this without further altering
Collection.transform()
seems silly offhand; feels like we want to do one of:transform
may sometimes be handedNone
and will do the right thing with it (becomes the identity function, basically, and hands None back to you), and change its signature to read eg:def transform(self, name: Union[str, None]) -> Union[str, None]:
.transform
will be running type-checking, will never be handing it anything butstr
, and nuke the escape-hatch at the top of the methodMy "hasn't done much typing but has done lots of maintaining" gut says option 1 is the right move here: less behavior/code change (as in a tiny amount would still be more than zero!) and in line with original intent of first implementation ("this method will be liberal in what it accepts").
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.
If it's internal code, not part of the API, I'd probably go for the second option if it results in cleaner code.
If you go for the first option though, you'll want to type as:
Which means the return type is the same as the parameter.
i.e.
reveal_type(transform("foo"))
would give youstr
. If you used unions, it'd give youstr | 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.
IMO transform doesn't actually do anything when
None
and passingNone
to every other caller would still require the checks. I'd rather throw an exception TBH.