[Python-checkins] peps: Update PEP 515: new, much simpler rule.

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


https://hg.python.org/peps/rev/39a195d1ee9c
changeset:   6224:39a195d1ee9c
user:        Georg Brandl <georg at python.org>
date:        Thu Feb 11 08:57:12 2016 +0100
summary:
  Update PEP 515: new, much simpler rule.

files:
  pep-0515.txt |  50 ++++++++++++++++------------------------
  1 files changed, 20 insertions(+), 30 deletions(-)


diff --git a/pep-0515.txt b/pep-0515.txt
--- a/pep-0515.txt
+++ b/pep-0515.txt
@@ -37,34 +37,18 @@
 Specification
 =============
 
-The current proposal is to allow underscores anywhere in numeric literals, with
-these exceptions:
-
-* Leading underscores cannot be allowed, since they already introduce
-  identifiers.
-* Trailing underscores are not allowed, because they look confusing and don't
-  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 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.
+The current proposal is to allow one or more consecutive underscores following
+digits and base specifiers in numeric literals.
 
 The production list for integer literals would therefore look like this::
 
    integer: decimalinteger | octinteger | hexinteger | bininteger
-   decimalinteger: nonzerodigit [decimalrest] | "0" [("0" | "_")* "0"]
+   decimalinteger: nonzerodigit (digit | "_")* | "0" ("0" | "_")*
    nonzerodigit: "1"..."9"
-   decimalrest: (digit | "_")* digit
    digit: "0"..."9"
-   octinteger: "0" ("o" | "O") (octdigit | "_")* octdigit
-   hexinteger: "0" ("x" | "X") (hexdigit | "_")* hexdigit
-   bininteger: "0" ("b" | "B") (bindigit | "_")* bindigit
+   octinteger: "0" ("o" | "O") (octdigit | "_")*
+   hexinteger: "0" ("x" | "X") (hexdigit | "_")*
+   bininteger: "0" ("b" | "B") (bindigit | "_")*
    octdigit: "0"..."7"
    hexdigit: digit | "a"..."f" | "A"..."F"
    bindigit: "0" | "1"
@@ -72,11 +56,12 @@
 For floating-point and complex literals::
 
    floatnumber: pointfloat | exponentfloat
-   pointfloat: [intpart] "_"* "." intpart | intpart "_"* "."
-   exponentfloat: (intpart | pointfloat) "_"* exponent
-   intpart: digit [(digit | "_")* digit]
-   exponent: ("e" | "E") "_"* ["+" | "-"] digit [decimalrest]
-   imagnumber: (floatnumber | intpart) "_"* ("j" | "J")
+   pointfloat: [intpart] fraction | intpart "."
+   exponentfloat: (intpart | pointfloat) exponent
+   intpart: digit (digit | "_")*
+   fraction: "." intpart
+   exponent: ("e" | "E") ["+" | "-"] intpart
+   imagnumber: (floatnumber | intpart) ("j" | "J")
 
 
 Further Considerations
@@ -131,11 +116,16 @@
 rules into three major groups.  In cases where the language spec contradicts the
 actual behavior, the actual behavior is listed.
 
-**Group 1: liberal (like this PEP)**
+**Group 1: liberal**
+
+This group is the least homogeneous: the rules vary slightly between languages.
+All of them allow trailing underscores.  Some allow underscores after non-digits
+like the ``e`` or the sign in exponents.
 
 * D [2]_
-* Perl 5 (although docs say it's more restricted) [3]_
-* Rust [4]_
+* Perl 5 (underscores basically allowed anywhere, although docs say it's more
+  restricted) [3]_
+* Rust (allows between exponent sign and digits) [4]_
 * Swift (although textual description says "between digits") [5]_
 
 **Group 2: only between digits, multiple consecutive underscores**

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


More information about the Python-checkins mailing list