Fixes for datetime and relativedelta (#1191)

Fixes #1163.
This commit is contained in:
Jelle Zijlstra
2017-04-22 15:52:55 -07:00
committed by Guido van Rossum
parent 8dc082dce5
commit 1350d7e4d2
2 changed files with 31 additions and 26 deletions

View File

@@ -3,7 +3,7 @@
# NOTE: These are incomplete!
from time import struct_time
from typing import Optional, SupportsAbs, Tuple, Union, overload
from typing import AnyStr, Optional, SupportsAbs, Tuple, Union, overload
MINYEAR = 0
MAXYEAR = 0
@@ -39,7 +39,7 @@ class date(object):
def ctime(self) -> str: ...
def strftime(self, fmt: Union[str, unicode]) -> str: ...
def __format__(self, fmt: Union[str, unicode]) -> str: ...
def __format__(self, fmt: AnyStr) -> AnyStr: ...
def isoformat(self) -> str: ...
def timetuple(self) -> struct_time: ...
def toordinal(self) -> int: ...
@@ -84,7 +84,7 @@ class time:
def __hash__(self) -> int: ...
def isoformat(self) -> str: ...
def strftime(self, fmt: Union[str, unicode]) -> str: ...
def __format__(self, fmt: str) -> str: ...
def __format__(self, fmt: AnyStr) -> AnyStr: ...
def utcoffset(self) -> Optional[timedelta]: ...
def tzname(self) -> Optional[str]: ...
def dst(self) -> Optional[int]: ...
@@ -114,7 +114,7 @@ class timedelta(SupportsAbs[timedelta]):
def __add__(self, other: timedelta) -> timedelta: ...
def __radd__(self, other: timedelta) -> timedelta: ...
def __sub__(self, other: timedelta) -> timedelta: ...
def __rsub(self, other: timedelta) -> timedelta: ...
def __rsub__(self, other: timedelta) -> timedelta: ...
def __neg__(self) -> timedelta: ...
def __pos__(self) -> timedelta: ...
def __abs__(self) -> timedelta: ...
@@ -135,7 +135,7 @@ class timedelta(SupportsAbs[timedelta]):
def __hash__(self) -> int: ...
class datetime(object):
# TODO: is actually subclass of date, but __le__, __lt__, __ge__, __gt__ don't work with date.
# TODO: is actually subclass of date, but __le__, __lt__, __ge__, __gt__, __sub__ don't work with date.
min = ... # type: datetime
max = ... # type: datetime
resolution = ... # type: timedelta
@@ -176,7 +176,7 @@ class datetime(object):
@classmethod
def combine(cls, date: date, time: time) -> datetime: ...
def strftime(self, fmt: Union[str, unicode]) -> str: ...
def __format__(self, fmt: str) -> str: ...
def __format__(self, fmt: AnyStr) -> AnyStr: ...
def toordinal(self) -> int: ...
def timetuple(self) -> struct_time: ...
def utctimetuple(self) -> struct_time: ...

View File

@@ -1,8 +1,11 @@
from typing import Any, List, Optional, Union
from typing import overload, Any, List, Optional, SupportsFloat, TypeVar, Union
from datetime import date, datetime, timedelta
__all__ = ... # type: List[str]
_SelfT = TypeVar('_SelfT', bound=relativedelta)
_DateT = TypeVar('_DateT', date, datetime)
class weekday(object):
def __init__(self, weekday: int, n: Optional[int]=...) -> None: ...
@@ -49,38 +52,40 @@ class relativedelta(object):
@weeks.setter
def weeks(self, value: int) -> None: ...
def normalized(self) -> 'relativedelta': ...
def normalized(self: _SelfT) -> _SelfT: ...
def __add__(
self,
other: Union['relativedelta', timedelta, date, datetime]) -> 'relativedelta': ...
@overload
def __add__(self: _SelfT, other: relativedelta) -> _SelfT: ...
@overload
def __add__(self: _SelfT, other: timedelta) -> _SelfT: ...
@overload
def __add__(self, other: _DateT) -> _DateT: ...
@overload
def __radd__(self: _SelfT, other: timedelta) -> _SelfT: ...
@overload
def __radd__(self, other: _DateT) -> _DateT: ...
@overload
def __rsub__(self: _SelfT, other: timedelta) -> _SelfT: ...
@overload
def __rsub__(self, other: _DateT) -> _DateT: ...
def __sub__(self: _SelfT, other: relativedelta) -> _SelfT: ...
def __radd__(
self,
other: Any) -> 'relativedelta': ...
def __rsub__(
self,
other: Any) -> 'relativedelta': ...
def __sub__(self, other: 'relativedelta') -> 'relativedelta': ...
def __neg__(self) -> 'relativedelta': ...
def __neg__(self: _SelfT) -> _SelfT: ...
def __bool__(self) -> bool: ...
def __nonzero__(self) -> bool: ...
def __mul__(self, other: float) -> 'relativedelta': ...
def __mul__(self: _SelfT, other: SupportsFloat) -> _SelfT: ...
def __rmul__(self, other: float) -> 'relativedelta': ...
def __rmul__(self: _SelfT, other: SupportsFloat) -> _SelfT: ...
def __eq__(self, other) -> bool: ...
def __ne__(self, other: object) -> bool: ...
def __div__(self, other: float) -> 'relativedelta': ...
def __div__(self: _SelfT, other: SupportsFloat) -> _SelfT: ...
def __truediv__(self, other: float) -> 'relativedelta': ...
def __truediv__(self: _SelfT, other: SupportsFloat) -> _SelfT: ...
def __repr__(self) -> str: ...