-
Notifications
You must be signed in to change notification settings - Fork 965
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 annotations #427
Add type annotations #427
Conversation
0f309fd
to
ddd3676
Compare
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 a lot for doing this @MartinThoma! This looks really good. I love the types and the updated formatting 🚀
* Added 'repeat' decorator and written a test. Increased the version by 0.0.1. * Removed the type of the given job for python 2.* compatibility. * Added some newlines to comply with FLAKE8 * Added import for 'repeat' in the code example * Added decorator docs and the ability to pass arguments to the job through the decorator * Fix FLAKE8 * Added rhagenaars to authors * Apply suggestions from code review
Partial functions for example do not have a __name__, so they need the same treatment in __str__ as in __repr__ in order to show a name-like thing.
* Added conda to installation instructions * Update installation.rst
32ea7da
to
274e622
Compare
274e622
to
a3c3f80
Compare
There are 4 errors mentioned by mypy where I'm uncertain if they can be ignored:
|
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.
Almost there! Just a few nitpicky comments left.
And let's add a note in the docs about mypy.
schedule/__init__.py
Outdated
Can be returned from a job to unschedule itself. | ||
""" | ||
|
||
pass |
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 undo these removals of pass
and these formatting changes.
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 undid it. However, I want to point out that the "pass" has absolutely no effect here. It's like a comment. Pass only is necessary if nothing follows, e.g. if the docstring wasn't there.
@@ -157,7 +148,7 @@ def cancel_job(self, job): | |||
except ValueError: | |||
logger.debug('Cancelling not-scheduled job "%s"', str(job)) | |||
|
|||
def every(self, interval=1): | |||
def every(self, interval: int = 1) -> "Job": |
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.
def every(self, interval: int = 1) -> "Job": | |
def every(self, interval: int = 1) -> Job: |
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 will only work with from __future__ import annotations
as the class Job is not defined at this point. In Python < 3.8 the annotation is actually evaluated when the signature is parsed. Meaning the class "Job" would have to exist. Or we import the future annotations ... but that will also only do the trick for Python 3.7. There is no way around the quotes for Python 3.6
@@ -167,13 +158,13 @@ def every(self, interval=1): | |||
job = Job(interval, self) | |||
return job | |||
|
|||
def _run_job(self, job): | |||
def _run_job(self, job: "Job") -> 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.
def _run_job(self, job: "Job") -> None: | |
def _run_job(self, job: Job) -> 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.
Same comment as above
schedule/__init__.py
Outdated
self.scheduler = scheduler # scheduler to register with | ||
|
||
def __lt__(self, other): | ||
def __init__(self, interval, scheduler: Scheduler = 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.
add explicit type to interval
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! I made it an int :-)
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 looks good to go! Really great work @MartinThoma!!!!
Thank you very much for all the support for this PR and work on schedule in general 🤗 |
No description provided.