bpo-30302 Make timedelta.__repr__ more informative. (#1493)

This commit is contained in:
Utkarsh Upadhyay 2017-07-25 23:51:33 +02:00 committed by Victor Stinner
parent 830080913c
commit cc5a65cd90
6 changed files with 73 additions and 32 deletions

View file

@ -454,20 +454,18 @@ class timedelta:
return self
def __repr__(self):
if self._microseconds:
return "%s.%s(%d, %d, %d)" % (self.__class__.__module__,
self.__class__.__qualname__,
self._days,
self._seconds,
self._microseconds)
args = []
if self._days:
args.append("days=%d" % self._days)
if self._seconds:
return "%s.%s(%d, %d)" % (self.__class__.__module__,
self.__class__.__qualname__,
self._days,
self._seconds)
return "%s.%s(%d)" % (self.__class__.__module__,
args.append("seconds=%d" % self._seconds)
if self._microseconds:
args.append("microseconds=%d" % self._microseconds)
if not args:
args.append('0')
return "%s.%s(%s)" % (self.__class__.__module__,
self.__class__.__qualname__,
self._days)
', '.join(args))
def __str__(self):
mm, ss = divmod(self._seconds, 60)