-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add type hints #22
Add type hints #22
Conversation
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.
Thanks for the contrib.
Other changes I observed in my review:
- Reformatted the docstrings to prefer putting the content on the first line instead of aligning left.
- Restyled a docstring to replace a sentence with a section heading.
- Made some
None
return types explicit. - Whitespace tweaks.
- Updated docstrings to make the first line a proper sentence ending in a period.
For the future, please consider separating stylistic changes grouped into separate commits so they can be cherry-picked or excluded easily.
For example, I prefer the docstrings to start at the same level of indentation, as allowed by PEP 257. Changing the docstrings here implies that they should be changed across the 100 other projects I maintain and I'm not ready to accept that responsibility (and probably won't until a tool exists to autoformat that I can adopt programmatically, such as in jaraco/skeleton).
I'll roll back that change, but otherwise, this looks great, with just a few other minor things to consider besides the failing test, the most pressing concern.
jaraco/functools.py
Outdated
def reset(self): | ||
self.last_called = 0 | ||
def reset(self) -> None: | ||
self.last_called = 0.0 |
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.
Let's avoid changing the implementation when adding type annotations. Let's re-use the return type for time.time()
and the input type for time.sleep()
. Also below.
I don't know the answer to this either. Here's my thinking:
And in fact, the PEP addresses this concern specifically:
So yes, the proper solution is to move functools into its own package. |
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.
Thanks for this excellent review. Sorry for cumulating many types of changes in one commit. I will pay attention to it in the future PRs, including those to bring type annotations to other jaraco.*
projects :)
I've applied the suggested changes in docstrings and comments.
The remaining requests relate to type annotations being added in the runtime module, so do you mind if I go ahead and create a stub file and migrate all annotations there instead of resolving these requests for now?
I'm thinking of making jaraco.functools
a package by the way when moving the annotations to the stub file.
Fine by me. Thanks!
Also fine. Let me know if it would help for me to do this in main first.
I don't know why I can't reply to the thread, but yes, please propose behavioral changes in a separate change (although I think |
Thanks :) I think it's fine if it's done in this branch (since we migrate to the package format only due to the added type hints) unless you find any other reason to apply the change in main beforehand. My changes are ready, submitted below.
I don't know either. Sorry, I must have messed something up. Sure, I will propose the changes separately. ( |
Tested against
|
An alternative that just came to my mind right now: submit the stub to typeshed and leave
If the stub was submitted directly to typeshed, migrating
With that approach fixed, after submitting the stub to typeshed, I could actually create a separate PR here that simply removes all type annotations from |
My instinct is that's a suboptimal approach because it creates too much distance between the typespec and the implementation, allowing them to diverge. In theory, the type spec should be reflected/inferred from the implementation and thus evolve with the implementation. I've always considered typeshed a forward-compatibility layer until a world exists where the underlying libraries supply their own type specs. That said, I'm not philosophically opposed; it just feels like the wrong fit. If there are examples or documentation where using typeshed is recommended for cases such as these, I'd be less reluctant. My preference is still to convert the module to a package. There are many other cases where that becomes necessary (such as adding compatibility modules or breaking the package into semantic groupings), so I consider the barrier to promoting a module to a package to be minimal. |
Sure! Well then, I'll revert the implementation change and resolve the issues reported by the workflow and by pylance. Thanks for your feedback. |
@jaraco Could you approve the workflow please? I think it might be it! |
Sorry, my bad! I imported |
This looks great. Thanks for working through the issues and coming up with a valuable, broad improvement. |
Thanks! More stubs coming soon. 🚀 |
This change is implicated in jaraco/pip-run#79. |
@@ -18,6 +18,7 @@ include_package_data = true | |||
python_requires = >=3.8 | |||
install_requires = | |||
more_itertools | |||
typing_extensions; python_version < "3.11" |
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.
This pull request confuses me. The type annotations are added as stubs, which means that they aren't used at runtime at all -- only by e.g. mypy. Why is a runtime dependency added here?
This forces an additional module to be installed when installing jaraco.functools.
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 suspect the dependency was necessary when the hints were inline. Feel free to send a PR to remove. If tests pass, it’s good to go
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.
Done: #25
py.typed
marker (which would probably affect otherjaraco/...
modules(?), so please let me know whether I should revert adding that)P
andR
(previouslyCallableT
was ignored). Could you please check if docs build as they should? I didn't figure out how to build it myselftyping_extensions
dependency for Python versions <=3.10 (Concatenate
andParamSpec
are used)And a bonus
identity()
documentationmethod_caller
, now redirects tooperator.methodcaller