-
Notifications
You must be signed in to change notification settings - Fork 151
Add custom Duration and Timestamp classes with nanosecond support #975
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
base: main
Are you sure you want to change the base?
Conversation
def __init__(self, seconds: int = 0, nanoseconds: int = 0) -> None: | ||
"""Initialize a Duration with seconds and nanoseconds. | ||
|
||
Args: | ||
seconds: Number of seconds | ||
nanoseconds: Number of nanoseconds (0-999999999) | ||
|
||
Raises: | ||
TypeError: If seconds or nanoseconds are not integers | ||
ValueError: If nanoseconds is not between 0 and 999999999 | ||
""" | ||
if not isinstance(seconds, int): | ||
raise TypeError("seconds must be an integer") | ||
if not isinstance(nanoseconds, int): | ||
raise TypeError("nanoseconds must be an integer") |
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.
Why do we need this type check when we explicitly stated that in the function arguments?
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.
The type in the arguments are only "hints" for the linter, but python does not enforce them.
self.nanoseconds = nanoseconds | ||
|
||
@classmethod | ||
def from_timedelta(cls, td: timedelta) -> "Duration": |
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 is returning "Duration" with quotes. Is this expected?
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.
Yes. In Python you cannot use a type before introduced. This is a workaround introduced at some point:
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
What changes are proposed in this pull request?
Add custom Duration and Timestamp classes with nanosecond support
How is this tested?
Added tests
NO_CHANGELOG=true