This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: datetime types don't work as bases
Type: Stage:
Components: Extension Modules Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: tim.peters Nosy List: gvanrossum, tim.peters
Priority: normal Keywords:

Created on 2003-04-14 04:58 by tim.peters, last changed 2022-04-10 16:08 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
datetime.fix gvanrossum, 2003-04-14 17:26 Strawman fix
Messages (6)
msg15446 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2003-04-14 04:58
This is probably shallow.  Assigned to Guido in case 
it's very shallow <wink>:

>>> from datetime import *
>>> class C(date):
...     def whatever(self):
...         return "oops"
>>> c = C(2002, 1, 1)
>>> c.whatever()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'datetime.date' object has no 
attribute 'whatever'
>>> type(c)
<type 'datetime.date'>
>>>

Was reported on c.l.py.
msg15447 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2003-04-14 12:04
Logged In: YES 
user_id=6380

Well, one shallow thing becomes obvious when you write
c.__class__: it's date, not C! Back to Tim...
msg15448 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2003-04-14 17:26
Logged In: YES 
user_id=6380

Here's a strawman fix. It makes 'date' a properly
subclassable type, and makes all the other types (except
tzinfo) non-subclassable.
msg15449 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2003-04-14 22:02
Logged In: YES 
user_id=31435

I think the date enhancement is fine -- check it in!  I'd leave off 
removing the basetype flag on the other types, though -- I 
expect we'll need to make them subclassable too.
msg15450 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2003-04-14 22:20
Logged In: YES 
user_id=6380

Done; the rest is up to you!
msg15451 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2003-05-17 17:40
Logged In: YES 
user_id=31435

I checked in changes (for 2.3b2) so that time, datetime, 
and timedelta are properly subclassable from Python too.  
That's all of 'em, so closing this now.
History
Date User Action Args
2022-04-10 16:08:07adminsetgithub: 38298
2003-04-14 04:58:53tim.peterscreate