[Python-ideas] Allow attribute references for decimalinteger

אלעזר elazarg at gmail.com
Thu Oct 31 02:01:12 CET 2013


There's an unnecessary corner case regarding integer literals and attributes:
>>> 1..real
1.0
>>> 1.0.real
1.0
>>> 1..real
1.0
>>> 1. .real
1.0
>>> .1.real
0.1
>>> 1 .real
1
>>> (1).real
1
>>> 1.real
  File "<stdin>", line 1
    1.real
         ^
SyntaxError: invalid syntax

Why does it fail? To my human eyes it seems (almost) completely
unambiguous. Is it a lexing thing? I couldn't find an explanation (or
any reference at all, although there should be) in the docs.
The only ambiguity I can see is 1.j - but the desired meaning is
clear: 1j (just like 1.0j).

It may confuse beginners; it made me believe that there's no such
thing as 1.__class__ a couple of years ago. I guess it's bad for code
generators too.

I suggest making "1.identifier" legal, and adding `j` and `J`
properties to numbers.Number to mean the sensible thing (so 0.j is not
a special syntax as it today).

Elazar


More information about the Python-ideas mailing list