En Tue, 02 Jun 2009 03:14:22 -0300, Chris Rebert <c...@rebertia.com> escribió:

On Mon, Jun 1, 2009 at 10:25 PM, Alexandr N Zamaraev <to...@promsoft.ru> wrote:

import datetime as dt
d = dt.date(2009, 10, 15)
dt.date(d)
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
TypeError: function takes exactly 3 arguments (1 given)

Why int form int, str from str, Decumal from Decumal can construct bat date from date not?

Probably because the function signatures would be so different. str(),
int(), etc *always* take *exactly one* argument -- the object to
convert. In contrast, date() takes several integers corresponding to
the year, month, and day. Adding a second signature to it that took
exactly one argument (of type `date`) and copied it would be
significantly different from its other signature; in idiomatic Python,
one would typically make a separate, new function for this drastically
different signature.

That doesn't convince me. It's not very consistent along the various types: int("3ab0",16) is rather different than int(3.2) but they're the same function...

However, the `date` type is immutable, so there's no reason at all to
try and copy a new instance from an existing one anyway, thus a
single-argument copy-constructor is completely unnecessary, hence why
there isn't one.

Isn't the same for all other examples (int, float, str, Decimal...)? They're all immutable types, and some have several and rather different constructor signatures:

py> Decimal((0, (1, 5, 0, 0), -3))
Decimal('1.500')
py> Decimal(Decimal('1.500'))
Decimal('1.500')

If one can say float(3.0), str("hello"), etc -- what's so wrong with date(another_date)?

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to