[Python-checkins] peps: Update PEP 515 with corrections.

georg.brandl python-checkins at python.org
Thu Feb 11 02:57:23 EST 2016


https://hg.python.org/peps/rev/292a4c58bfed
changeset:   6223:292a4c58bfed
user:        Georg Brandl <georg at python.org>
date:        Thu Feb 11 08:45:52 2016 +0100
summary:
  Update PEP 515 with corrections.

files:
  pep-0515.txt |  46 +++++++++++++++++++++++++++++----------
  1 files changed, 34 insertions(+), 12 deletions(-)


diff --git a/pep-0515.txt b/pep-0515.txt
--- a/pep-0515.txt
+++ b/pep-0515.txt
@@ -13,7 +13,7 @@
 ======================
 
 This PEP proposes to extend Python's syntax so that underscores can be used in
-integral and floating-point number literals.
+integral, floating-point and complex number literals.
 
 This is a common feature of other modern languages, and can aid readability of
 long literals, or literals whose value should clearly separate into parts, such
@@ -30,6 +30,9 @@
     # grouping bits into bytes in a binary literal
     flags = 0b_0011_1111_0100_1110
 
+    # making the literal suffix stand out more
+    imag = 1.247812376e-15_j
+
 
 Specification
 =============
@@ -43,12 +46,12 @@
   contribute much to readability.
 * The number base prefixes ``0x``, ``0o``, and ``0b`` cannot be split up,
   because they are fixed strings and not logically part of the number.
-* No underscore allowed after a sign in an exponent (``1e-_5``), because
-  underscores can also not be used after the signs in front of the number
-  (``-1e5``).
-* No underscore allowed after a decimal point, because this leads to ambiguity
-  with attribute access (the lexer cannot know that there is no number literal
-  in ``foo._5``).
+* No underscore allowed immediately after a sign in an exponent (``1e-_5``),
+  because underscores can also not be used after the signs in front of the
+  number (``-1e5``).
+* No underscore allowed immediately after a decimal point, because this leads to
+  ambiguity with attribute access (the lexer cannot know that there is no number
+  literal in ``foo._5``).
 
 There appears to be no reason to restrict the use of underscores otherwise.
 
@@ -66,14 +69,28 @@
    hexdigit: digit | "a"..."f" | "A"..."F"
    bindigit: "0" | "1"
 
-For floating-point literals::
+For floating-point and complex literals::
 
    floatnumber: pointfloat | exponentfloat
-   pointfloat: [intpart] fraction | intpart "."
-   exponentfloat: (intpart | pointfloat) exponent
-   intpart: digit (digit | "_")*
-   fraction: "." intpart
+   pointfloat: [intpart] "_"* "." intpart | intpart "_"* "."
+   exponentfloat: (intpart | pointfloat) "_"* exponent
+   intpart: digit [(digit | "_")* digit]
    exponent: ("e" | "E") "_"* ["+" | "-"] digit [decimalrest]
+   imagnumber: (floatnumber | intpart) "_"* ("j" | "J")
+
+
+Further Considerations
+======================
+
+This PEP currently only proposes changing the literal syntax.  The following
+extensions are open for discussion:
+
+* Allowing underscores in string arguments to the ``Decimal`` constructor.  It
+  could be argued that these are akin to literals, since there is no Decimal
+  literal available (yet).
+
+* Allowing underscores in string arguments to ``int()``, ``float()`` and
+  ``complex()``.
 
 
 Alternative Syntax
@@ -88,6 +105,11 @@
 * Only one consecutive underscore allowed, and only between digits.
 * Multiple consecutive underscore allowed, but only between digits.
 
+A less common rule would be to allow underscores only every N digits (where N
+could be 3 for decimal literals, or 4 for hexadecimal ones).  This is
+unnecessarily restrictive, especially considering the separator placement is
+different in different cultures.
+
 Different Separators
 --------------------
 

-- 
Repository URL: https://hg.python.org/peps


More information about the Python-checkins mailing list