The date class is a immutable object, so you need to override the __new__()
static method instead:
class Foo(date):
def __new__(cls, year, month=1, day=1):
return super(Foo, cls).__new__(cls, year, month, day)
Note that you need to set the month and day to 1 at least, 0 is not a permissible value for the month
and day
arguments.
Using __new__
works:
>>> class Foo(date):
... def __new__(cls, year, month=1, day=1):
... return super(Foo, cls).__new__(cls, year, month, day)
...
>>> Foo(2013)
Foo(2013, 1, 1)