Arrow: Consider changing __repr__ for Arrow

Created on 28 Jul 2020  路  5Comments  路  Source: arrow-py/arrow

Here are the current str and repr methods for Arrow.

(arrow) chris@ThinkPad:~/arrow$ python
Python 3.8.3 (default, Jul  7 2020, 18:57:36) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import arrow
>>> dt=arrow.utcnow()
>>> str(dt)
'2020-07-27T22:38:46.653869+00:00'
>>> print(dt)
2020-07-27T22:38:46.653869+00:00
>>> repr(dt)
'<Arrow [2020-07-27T22:38:46.653869+00:00]>'

__str__ should be human readable which I think is achieved, however __repr__ is designed for debugging and therefore needs to be explicit. It's also nice (but not required) if the __repr__ can be instantiated into a new object.

This would be a breaking change so fits well for 1.0.0 if we decide to do it.

proposal

Most helpful comment

We should aim for a __repr__ similar to that of datetime: https://stackoverflow.com/a/19597196/3820660.

All 5 comments

Hello, I would like to implement this feature. It seems that currently, __repr__ is "[class_name] + __str__". Can you be more specific with what additional data __repr__ would need to have?

We should aim for a __repr__ similar to that of datetime: https://stackoverflow.com/a/19597196/3820660.

How about this?

>>> repr(dt)
arrow.Arrow(2020, 7, 27, 22, 38, 46, 653869, tzinfo=tzutc())

@yiransii it might be better if @systemcatch takes this on since he has had a design in mind for the repr for a while.

We have decided not to proceed with this change.

Was this page helpful?
0 / 5 - 0 ratings