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
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions third_party/2and3/datetimerange/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from typing import Any, Optional, Union, Iterable
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):

NOT_A_TIME_STR: str = ...
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.

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.)

def __eq__(self, other) -> bool: ...
def __ne__(self, other) -> bool: ...
def __add__(self, other) -> DateTimeRange: ...
def __iadd__(self, other) -> DateTimeRange: ...
def __sub__(self, other) -> DateTimeRange: ...
def __isub__(self, other) -> DateTimeRange: ...
def __contains__(self, x) -> bool: ...
@property
def start_datetime(self) -> datetime.datetime: ...
@property
def end_datetime(self) -> datetime.datetime: ...
@property
def timedelta(self) -> datetime.timedelta: ...
def is_set(self) -> bool: ...
def validate_time_inversion(self) -> None: ...
def is_valid_timerange(self) -> bool: ...
def is_intersection(self, x) -> bool: ...
def get_start_time_str(self) -> str: ...
def get_end_time_str(self) -> str: ...
def get_timedelta_second(self) -> float: ...
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.

def set_time_range(self, start: Union[datetime.datetime, str], end: Union[datetime.datetime, str]) -> None: ...
def range(self, step: Union[datetime.timedelta, relativedelta]) -> Iterable[datetime.datetime]: ...
def intersection(self, x: DateTimeRange) -> DateTimeRange: ...
def encompass(self, x: DateTimeRange) -> DateTimeRange: ...
def truncate(self, percentage: float) -> None: ...