[Python-ideas] Deprecate the round builtin
Joshua Landau
joshua.landau.ws at gmail.com
Mon Oct 1 00:19:33 CEST 2012
On 30 September 2012 23:08, Case Van Horsen <casevh at gmail.com> wrote:
> On Sun, Sep 30, 2012 at 2:51 PM, Joshua Landau
> <joshua.landau.ws at gmail.com> wrote:
> > On 30 September 2012 22:48, Joshua Landau <joshua.landau.ws at gmail.com>
> > wrote:
> >>
> >> This seems like a problem for the proposal, though: we can't have it in
> >> the math library if it's a method!
> >
> >
> > Now I think about it: yeah, it can be. We just coerce to float/decimal
> > first. *sigh*
> math.ceil(x), math.floor(x), and math.trunc(x) and round(x) already
> call the special methods x.__ceil__, x.__floor__, x.__round__, and
> x.__trunc__. So those four functions already work with decimal
> instances (and other numeric types that support those methods.)
>
>>> math.ceil("")
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: *a float is required*
How deceptive... I hope you forgive me for not realizing that (even though
I must have seen the __ceil__ and __floor__ methods a thousand times).
OK, carry on.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120930/da979561/attachment.html>
More information about the Python-ideas
mailing list