[issue30302] Improve .__repr__ implementation for datetime.timedelta

Utkarsh Upadhyay report at bugs.python.org
Tue Jun 27 08:32:22 EDT 2017


Utkarsh Upadhyay added the comment:

I've added the following tests to remove the 0 attributes from the repr:

        self.assertEqual(repr(self.theclass(days=1, seconds=0)),
                         "%s(days=1)" % name)
        self.assertEqual(repr(self.theclass(seconds=60)),
                         "%s(seconds=60)" % name)
        self.assertEqual(repr(self.theclass()),
                         "%s(seconds=0)" % name)
        self.assertEqual(repr(self.theclass(microseconds=100)),
                         "%s(microseconds=100)" % name)
        self.assertEqual(repr(self.theclass(days=1, microseconds=100)),
                         "%s(days=1, microseconds=100)" % name)
        self.assertEqual(repr(self.theclass(seconds=1, microseconds=100)),
                         "%s(seconds=1, microseconds=100)" % name)

I am still ambivalent about factoring the minus sign outside, though.

I've also fixed a bug in test_datetime.py which prevented execution of the Python implementation in Lib/datetime.py.


TODO:

  - Decide about factoring the minus sign.
  - Drop description of timedelta.__repr__ from the documentation.

~
ut

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30302>
_______________________________________


More information about the Python-bugs-list mailing list