On 4/25/2011 1:21 PM, Rob Cliffe wrote:
 >>> type (3.)
<type 'float'>
 >>> 3..__class__
<type 'float'>
 >>> type(3)
<type 'int'>
 >>> 3.__class__
File "<stdin>", line 1
3.__class__
^
SyntaxError: invalid syntax

Superficially the last example ought to be legal syntax (and return
<type 'int'>).

You are a more sophisticated parser than Python, which is limited to LL(1) parsing. (No that is not in the manual, but it is a known design consraint.)

Is it an oversight which could be fixed in a straightforward way, or are
there reasons why it can't?

This sort of question as to why Python is the way it is really belongs on python-list.

3.x is parsed as (3.)x (float 3. followed by x) which is invalid syntax unless 'x' is a digit(s). You automatically back up and reparse as 3(.x)
3 .0 is a syntax error.
3 .__class__ is int.

--
Terry Jan Reedy

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to