[Python-Dev] Syntax quirk (original) (raw)

Nick Coghlan ncoghlan at gmail.com
Mon Apr 25 19:36:11 CEST 2011


On Tue, Apr 26, 2011 at 3:21 AM, Rob Cliffe <rob.cliffe at btinternet.com> wrote:

type (3.) <type 'float'> 3..class <type 'float'> type(3) <type 'int'> 3.class  File "", line 1  3.class  ^ SyntaxError: invalid syntax Superficially the last example ought to be legal syntax (and return <type_ _'int'>). Is it an oversight which could be fixed in a straightforward way, or are there reasons why it can't?

The parser (or is it the lexer? I never remember which it is that has the problem in this case) can't handle it - it sees the first "." and expects a floating point value. It's hard to disambiguate due to 3.e10 and the like being valid floating point numbers, while 3..e10 has to be an attribute access.

You have to use whitespace or parentheses to eliminate the ambiguity:

  1. class (3).class

Cheers, Nick.

-- Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-Dev mailing list