[Python-ideas] In call grammar, replace primary with possible_call? (was Re: ...quote followed by a left parenthesis...?)
Chris Angelico
rosuav at gmail.com
Fri Jul 17 03:54:19 CEST 2015
More information about the Python-ideas mailing list
Fri Jul 17 03:54:19 CEST 2015
- Previous message (by thread): [Python-ideas] In call grammar, replace primary with possible_call? (was Re: ...quote followed by a left parenthesis...?)
- Next message (by thread): [Python-ideas] In call grammar, replace primary with possible_call? (was Re: ...quote followed by a left parenthesis...?)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, Jul 17, 2015 at 11:44 AM, Andrew Barnert via Python-ideas <python-ideas at python.org> wrote: > To a normal end-user, the things you syntactically call are basically all values (or, if you prefer, all expressions). Calling a value that's not callable is the same error as adding a thing that's not addable or indexing a thing that's not subscriptable, and that's a TypeError. The existing rules makes sense, and fit in with everything else in Python. For example, we don't consider {1}[1] a syntax error even though it's never valid; how is {1}(1) any different? > There are other odd cases in the grammar, too, though. Try explaining this one: >>> x = 1 >>> x.to_bytes(4,"little") b'\x01\x00\x00\x00' >>> 1.to_bytes(4,"little") File "<stdin>", line 1 1.to_bytes(4,"little") ^ SyntaxError: invalid syntax >>> (1).to_bytes(4,"little") b'\x01\x00\x00\x00' If the grammar can catch an error, great! If it can't, it'll get dealt with at run-time. Syntax errors don't have to be reserved for situations that make it impossible to proceed at all. ChrisA
- Previous message (by thread): [Python-ideas] In call grammar, replace primary with possible_call? (was Re: ...quote followed by a left parenthesis...?)
- Next message (by thread): [Python-ideas] In call grammar, replace primary with possible_call? (was Re: ...quote followed by a left parenthesis...?)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list