[Python-ideas] Python Numbers as Human Concept Decimal System

Andrew Barnert abarnert at yahoo.com
Sat Mar 8 23:15:43 CET 2014


On Mar 8, 2014, at 12:12, Chris Angelico <rosuav at gmail.com> wrote:

> It's probably time someone [1] wrote up a PEP about all this.

> The most
> important points, as I see it, are:
> 
> 1) Create a new Decimal literal notation - 1.234d seems to be the most
> popular syntax. This is reasonably uncontroversial, but it has
> consequences.

1a) Move the Decimal type's implementation out of the module and into Objects, or make it a frozen module that's always loaded at startup, or invent some scheme to load it as needed.

1b) Possibly move the type to builtins? (Certainly not necessary--function is a built-in type, and you can create them without importing anything, but the type lives in types, not builtins.)

1c) Possibly add the implementation to the public C API? (With which methods? FromString, but what about From/AsDouble? Is there any need to From/AsTuple from C? Inspect the object in any other way? Get/set the current context?)

> 2) Create a new float literal notation - 1.234f or 1.234r or any of
> the other proposals.
> 3) Possibly change repr(float) to include the tag.

3a) Change repr(Decimal) to use the new literal.

> 4) Introduce a "from __future__ import decimal_literals" (named to
> parallel unicode_literals - you can get a u"literal" without that
> directive, but the default literal type becomes unicode)
> 5) What about int/int? Should that now be Decimal? Should it be per-module???
> 6) Further cans of worms like #5
> 
> Introducing 1/2/4 would let you stick the future directive into
> PYTHONSTARTUP and then run Python as an interactive decimal
> calculator.




More information about the Python-ideas mailing list