[Python-Dev] PEP 0484 - the Numeric Tower

Oscar Benjamin oscar.j.benjamin at gmail.com
Wed Oct 14 18:49:33 EDT 2015

On 14 Oct 2015 23:06, "Laura Creighton" <lac at openend.se> wrote:
> In a message of Wed, 14 Oct 2015 21:21:30 -0000, Oscar Benjamin writes:
> >Generally if it's possible to interchange floats and decimals in your
> >then there's probably no need for decimals in the first place.
> Yes, but, at least around here the common case is that you already
> _have_ a pile of decimals (extracted from your leger) and now you
> want to do something with them (like graph them and make reports
> out of the graphs) with other people's graphing and report generating
> software.

The graphing library will almost certainly convert your data to float so
I'd say this comes under the category of: you don't need decimals here.

> >If mypy
> >requires you to do an explicit conversion to float then there may be some
> >seld-documenting merit in showing that conversion up front rather than
> >assuming that it's okay to insert decimals where they're not expected.
> >point of static type checking is to detect precisely these kinds of
> The thing is that there is a very big split between code written as
> 'this is a float using function and decimal users very much have to
> avoid using it' and 'this thing works perfectly well for floats and
> decimals'.  That code writers in the scientific python world mostly
> never think of Decimal users, doesn't mean they don't end up writing
> perfectly wonderful tools and libraries we use. :)  thankfully :)
> I was looking for a way for the Python type hinting to be expressive
> enough to handle this common (at least in my world) case.  So then,
> even if the bokeh developers (just to pick some friends) forget about
> me in their type annotations, I can just make a pull request, send it
> back with some corrected annotations and the note 'remember me!' :)

I'm sure the bokeh developers will be aware of the different ways that
their library is used (at this level). If the input spec is "sequence of
coercible to float" then I agree that they should use type annotations to
match that rather than putting float and I imagine they would welcome your

Guido's suggestion is not general enough for that though: what about
Fraction, mpf, gmpy, numpy, sympy, h5py etc? The ABCs in the numeric tower
are unused by 3rd party types making them useless for abstract type
inference (IMO). AFAIK the lowest common denominator among number types in
Python is the __float__ special method. Does mypy have a way to require (a
sequence of) that?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20151014/87348ed6/attachment.html>

More information about the Python-Dev mailing list