[Python-Dev] Symmetry arguments for API expansion

Alexander Belopolsky alexander.belopolsky at gmail.com
Mon Mar 12 18:21:30 EDT 2018


On Mon, Mar 12, 2018 at 5:18 PM, Tim Peters <tim.peters at gmail.com> wrote:
> [Guido]
>> .... as_integer_ratio() seems mostly cute (it has Tim Peters all
>> over it),
>
> Nope!  I had nothing to do with it.  I would have been -0.5 on adding
> it had I been aware at the time.
>
> - I expect the audience is tiny.

The datetime module would benefit from having as_integer_ratio()
supported by more types.  It's been hard to resist requests to allow
Decimal in timedelta constructors and/or arithmetics

>>> timedelta(Decimal('1.5'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported type for timedelta days component: decimal.Decimal

but

>>> timedelta(1.5)
datetime.timedelta(days=1, seconds=43200)

I don't recall why we decided not to accept anything with an
.as_integer_ratio() method.

See <https://bugs.python.org/issue14262> for additional discussion.


More information about the Python-Dev mailing list