diff options
| author | Utkarsh Upadhyay <mail@musicallyut.in> | 2017-07-25 23:51:33 +0200 |
|---|---|---|
| committer | Victor Stinner <victor.stinner@gmail.com> | 2017-07-25 23:51:33 +0200 |
| commit | cc5a65cd9025280ea67ef4bbc2a8bfe31ced6c30 (patch) | |
| tree | 4565cd48860cd2c8581225565509ea327293b7f9 /Lib/datetime.py | |
| parent | 830080913c22a9834d310294b9f7653234dc6a59 (diff) | |
| download | cpython-git-cc5a65cd9025280ea67ef4bbc2a8bfe31ced6c30.tar.gz | |
bpo-30302 Make timedelta.__repr__ more informative. (#1493)
Diffstat (limited to 'Lib/datetime.py')
| -rw-r--r-- | Lib/datetime.py | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/Lib/datetime.py b/Lib/datetime.py index b95536fb7a..76a6f957e0 100644 --- a/Lib/datetime.py +++ b/Lib/datetime.py @@ -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) |
