[ python-Bugs-1448640 ] datetime.__init__ cannot be overridden
SourceForge.net
noreply at sourceforge.net
Mon Mar 13 05:54:45 CET 2006
Bugs item #1448640, was opened at 2006-03-13 04:54
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1448640&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Martin Blais (blais)
Assigned to: Nobody/Anonymous (nobody)
Summary: datetime.__init__ cannot be overridden
Initial Comment:
Hi
The following code does not work properly:
#!/usr/bin/env python
"""
Test overriding constructor of datetime classes.
"""
import sys, datetime
class MyDate(datetime.date):
def __init__( self, year, month, day ):
print >> sys.stderr, 'lose data'
d = MyDate(2006, 11, 29)
print d
class MyDate(datetime.date):
def __new__( self, year, month, day ):
print 'lose data'
def __init__( self, year, month, day ):
print 'lose data again'
d = MyDate(2006, 11, 29)
print d
The output is:
lose data
2006-11-29
lose data
None
The problem is that the initialization of the object is
done in its time_new() method which is registered for
__new__ rather than using an __init__ method. This
prevent one from overriding the date/datetime/time
constructors.
cheers,
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1448640&group_id=5470
More information about the Python-bugs-list
mailing list