Issue 671731: time module: time tuple not returned by certain functions (original) (raw)

Created on 2003-01-21 11:14 by mrmiller, last changed 2022-04-10 16:06 by admin. This issue is now closed.

Messages (7)
msg14139 - (view) Author: Martin Miller (mrmiller) Date: 2003-01-21 11:14
On win32 the gmtime() and localtime() functions in the time module return values of type 'time.time_struct'. I believe the proper return value should be a tuple. This is implied by the documentation (see <http://www.python.org/doc/current/lib/module-time.html> where it discusses the *time tuple* returned by the various module functions and says it 'is a tuple of 9 integers'. The time_struct value returned does behave like a tuple instance in most respects, except that its type is not type 'tuple'. I think this is something that was changed in the not too distant past, as I noticed the issue after downloading code recently written by others which depends on the type of the return value from these functions being a tuple. If nothing else, if this was changed, it is not backward compatible and the documention ought to be updated. Example: > Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import time > >>> print time.localtime() > (2003, 1, 21, 3, 3, 2, 1, 21, 0) > >>> print type(time.localtime()) is type(()) > 0 > >>> print type(time.localtime()) > <type 'time.struct_time'> > >>>
msg14140 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2003-01-21 11:40
Logged In: YES user_id=6656 This was very deliberate. It *is* a bit shocking that the docs didn't get updated, though. There's a start of a description in: http://www.python.org/doc/current/whatsnew/node10.html Do you have code that actually broke because of this change?
msg14141 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2003-01-22 00:55
Logged In: YES user_id=357491 There is a mention of it in the developer docs at http://www.python.org/dev/doc/devel/lib/module-time.html . The note for struct_time says what functions return a struct_time object. A patch for the docs that changed everything else to say it returns a struct_time object instead of a time tuple wouldn't hurt, though.
msg14142 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2003-01-22 10:08
Logged In: YES user_id=6656 Oh yeah. That should *definitely* be backported to the 2.2 docs. Could be more thorough, though.
msg14143 - (view) Author: Martin Miller (mrmiller) Date: 2003-01-24 20:55
Logged In: YES user_id=257085 The strcut_time return value change broke a module I had downloaded called NormalDate by Jeff Bauer <jbauer@rubic.com>. Fixing it myself turned out to be relatively easy, once I determined what was the problem (which was a little time-consuming, considering the fact that the docs hadn't been updated). Later I located an updated version of module (v1.3) that had been fixed by the author. The technique he used was to create a private module attribute set to the type of value returned from localtime(), so the updated module would still work with versions of Python < 2.2. The struct_time pseudo-sequence now returned by the functions now sounds like a useful improvement, provided that this fact is documented along with a description of what the type is, which would allow others to also take advantage of its attribute fetching behavior if they wished. This could be done by copying the description in <http://www.python.org/doc/current/whatsnew/node10.html> into the developer documentation for the the time module (and backporting that into the 2.2 documentation. I'm lowering the priorty to 3 and marking it as a documentation bug.
msg14144 - (view) Author: Martin Miller (mrmiller) Date: 2003-01-24 22:23
Logged In: YES user_id=257085 Looks like a duplicate of closed bug 604128 "time.struct_time undocumented" which was assigned and fixed by fdrake on 2002-11-13. However I've looked at the Doc/lib/libtime.tex file that included with 2.2.2 and see nothing written about the type. I'll try assigning this bug to him since I can't find the fix.
msg14145 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2003-02-04 15:19
Logged In: YES user_id=3066 The previous "fix" was pretty dodgy, I think, since I didn't have a lot of time for it. it really only added information about the attributes, but did not change references to time tuples throughout. Perhaps it should have remained open, pending a better fix. I've checked in additional changes that provide more thorough updates. Doc/lib/libtime.tex 1.55, 1.48.6.4.
History
Date User Action Args
2022-04-10 16:06:09 admin set github: 37811
2003-01-21 11:14:41 mrmiller create