[issue5907] repr of time.struct_time type does not eval

2009-05-03 Thread John Morton

John Morton  added the comment:

While it's true that repr() methods cannot generally be expected to eval
back into an object of the same type, the old repr behaviour of the
struct_time object did effectively do so. Admittedly it was a kludge due
to the time module functions originally producing a tuple before the
advent of the struct_time type, but code that expected repr->eval
behaviour worked up to 2.5. It's also evident that who ever changed the
behaviour of time.struct_time.__repr__ intended that to sill be the
case, otherwise it would have produced a string of the form 

So I would describe this as a bug, otherwise you'd have to call it an
undocumented behaviour change :-)

The question remains, how to fix it? Should the repr output change to
time.struct_time((tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec,
tm_wday, tm_yday, tm_isdst)) or implement the keyword argument form?

(Note: python3.0 shares this new behaviour)

--
versions: +Python 3.0

___
Python tracker 
<http://bugs.python.org/issue5907>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5907] repr of time.struct_time type does not eval

2009-05-02 Thread John Morton

New submission from John Morton :

The output of repr on an object of type time.struct_time has changed
from 2.5 to 2.6, and can no longer be read in with an eval.

2.5 behaviour:

Python 2.5.4 (r254:67916, Apr  4 2009, 17:55:16) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> t1 = time.gmtime()
>>> t1_repr = repr(t1)
>>> t1_repr
'(2009, 5, 2, 16, 16, 43, 5, 122, 0)'
>>> t2 = eval(t1_repr)
>>> t1 == t2
True

Meanwhile in 2.6:

Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> t1 = time.gmtime()
>>> t1_repr = repr(t1)
>>> t1_repr
'time.struct_time(tm_year=2009, tm_mon=5, tm_mday=2, tm_hour=16,
tm_min=20, tm_sec=54, tm_wday=5, tm_yday=122, tm_isdst=0)'
>>> t2 = eval(t1_repr)
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 1, in 
TypeError: structseq() takes at most 2 arguments (9 given)

Obviously returning a time.time_struct based representation is the right
thing to do, but the repr of this flavour should eval.

--
components: Extension Modules, Tests
messages: 86958
nosy: jwm
severity: normal
status: open
title: repr of time.struct_time type does not eval
type: behavior
versions: Python 2.6

___
Python tracker 
<http://bugs.python.org/issue5907>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com