Skip to content
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

Adding datetimerange stubs #3845

Merged
merged 7 commits into from
Mar 17, 2020
Merged

Adding datetimerange stubs #3845

merged 7 commits into from
Mar 17, 2020

Conversation

snallapa
Copy link
Contributor

Hello I was looking to use mypy and made stubs for a library that I was using. The library in question is this one https://github.com/thombashi/DateTimeRange . This is my first PR to typeshed so lmk if I missed anything!

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, a few things below.

import datetime
from dateutil.relativedelta import relativedelta

class DateTimeRange:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this stub is for Python 2 as well, this should use object as base class to mark this as a new-style class:

class DateTimeRange(object):

Comment on lines 7 to 10
start_time_format: str = ...
end_time_format: str = ...
is_output_elapse: bool = ...
separator: str = ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: = ... is redundant.

end_time_format: str = ...
is_output_elapse: bool = ...
separator: str = ...
def __init__(self, start_datetime: Optional[str], end_datetime: Optional[str], start_time_format: str = ..., end_time_format: str = ...) -> None: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

start_datetime and end_datetime have default values, so = ... is missing. (Optional is unfortunately slightly misnamed and does not indicate optional arguments.)

Comment on lines 32 to 33
def set_start_datetime(self, value: Union[datetime.datetime, str], timezone: str = ...) -> None: ...
def set_end_datetime(self, value: Union[datetime.datetime, str], timezone: str = ...) -> None: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the timezone arguments default to None, they should have Optional[str] as arguments since they obviously accept None as well.

@snallapa
Copy link
Contributor Author

Thank you for that! Knew I was going to make some mistakes. I made those changes and pushed just now

@srittau srittau merged commit 8e0af4e into python:master Mar 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants