[issue31263] Assigning to subscript/slice of literal is permitted

2017-08-22 Thread Isaac Elliott

New submission from Isaac Elliott:

In Python 3.5 and 3.6 (at least), the language reference presents a grammar 
that disallows assignment to literals.

For example, `(a for 1 in [1,2,3])` is a syntax error, as is `(1, a) = (2, 3)`.

However the grammar doesn't prevent assignment to subscripted or sliced 
literals.

For example neither `(a for [1,2,3][0] in [1,2,3])` nor `([1,2,3][0], a) = (2, 
3)` are considered syntax errors.

Similar behavior is exhibited for slices.

The problem is that the `target_list` production 
(https://docs.python.org/3.5/reference/simple_stmts.html#grammar-token-target_list)
 reuses the `subscription` and `slicing` productions which both use the 
`primary` production, allowing literals on their left side.

--
messages: 300740
nosy: Isaac Elliott
priority: normal
severity: normal
status: open
title: Assigning to subscript/slice of literal is permitted
type: behavior
versions: Python 3.5, Python 3.6

___
Python tracker 
<http://bugs.python.org/issue31263>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31263] Assigning to subscript/slice of literal is permitted

2017-08-23 Thread Isaac Elliott

Isaac Elliott added the comment:

Yes I would disallow a script such as
`a = [0]; [5, a][1][:] = [3]` (note: your example of just `[5, a][1][:] = [3]` 
does not run, so I assumed it must be used in a situation like this)

Evaluating the target of an assignment is unnecessary, we can syntactically 
determine whether some left hand side can be assigned to:

* Identifiers are assignable (`a = 2`)
* Attribute accesses are assignable, provided that the left of the dot is 
assignable (`a.foo = 2`, `a.b.c.foo`, etc)
* Subscripts are assignable, provided that the outer expression is assignable 
(`a[1] = 2`, `a.foo[b] = 2`, `a[1][2][3] = 2`, `a.b[1].c[2] = 2`)
* Lists are assignable, provided that all their elements are assignable 
(`[a,b,c] = [1,2,3]`)
* Expression lists/tuples are assignable, provided that all their elements are 
assignable (`a, b = (1, 2)`, `(a,b,c) = (1,2,3)`)
* Unpackings are assignable, provided that their argument is assignable (`*a, = 
[1,2,3]`, `a, *b = [1,2,3]`)
* Slices are assignable, provided that the outer expression is assignable 
(`a[:] = [1,2,3]`, `a.foo[1:2] = [1]`
* Everything else is not assignable (did I forget anything?)

This can definitely be encoded as a context-free grammar, although I don't know 
if it will present conflicts in the parser generator.

I do think it's worth it. Python is one of the most widely used programming 
languages, and it's our responsibility to ensure it behaves correctly.

--

___
Python tracker 
<http://bugs.python.org/issue31263>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31263] Assigning to subscript/slice of literal is permitted

2017-08-23 Thread Isaac Elliott

Isaac Elliott added the comment:

Does backward compatibility take priority over correct behavior? What process 
is followed when fixing a bug causes a breaking change?

--

___
Python tracker 
<http://bugs.python.org/issue31263>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33149] Parser stack overflows

2018-03-26 Thread Isaac Elliott

New submission from Isaac Elliott :

python3's parser stack overflows on deeply-nested expressions, for example:

[[]]

or

aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa(aa()

These are both minimal examples, so if you remove one level of nesting from 
either then python3 will behave normally.

--
messages: 314485
nosy: Isaac Elliott
priority: normal
severity: normal
status: open
title: Parser stack overflows
versions: Python 3.6

___
Python tracker 
<https://bugs.python.org/issue33149>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33149] Parser stack overflows

2018-03-26 Thread Isaac Elliott

Isaac Elliott  added the comment:

Because of the way recursive descent parsing works,

[[

is actually the minimal input required to reproduce this in python3.

In python2, the bug is still present, but requires a slightly deeper nesting:



--

___
Python tracker 
<https://bugs.python.org/issue33149>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33766] Grammar Incongruence

2018-06-03 Thread Isaac Elliott


New submission from Isaac Elliott :

echo 'print("a");print("b")' > test.py

This program is grammatically incorrect according to the specification 
(https://docs.python.org/3.8/reference/grammar.html). But Python 3 runs it 
without issue.


It's this production here

simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE

which says 'simple_stmt's must be terminated by a newline. However, the program 
I wrote doesn't contain any newlines.

I think the grammar spec is missing some information, but I'm not quite sure 
what. Does anyone have an idea?

--
components: Interpreter Core
messages: 318617
nosy: Isaac Elliott
priority: normal
severity: normal
status: open
title: Grammar Incongruence
type: behavior
versions: Python 3.5, Python 3.6, Python 3.7, Python 3.8

___
Python tracker 
<https://bugs.python.org/issue33766>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33766] Grammar Incongruence

2018-06-03 Thread Isaac Elliott


Isaac Elliott  added the comment:

Thanks for the clarification. Is there a reference to this in the documentation?

--

___
Python tracker 
<https://bugs.python.org/issue33766>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33766] Grammar Incongruence

2018-06-03 Thread Isaac Elliott


Isaac Elliott  added the comment:

I went through that document before I created this issue. I can't find anything 
which describes this behavior - could you be more specific please?

--

___
Python tracker 
<https://bugs.python.org/issue33766>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33766] Grammar Incongruence

2018-06-03 Thread Isaac Elliott


Isaac Elliott  added the comment:

Cool, thanks for the help. Should I submit a PR with the updated documentation?

--

___
Python tracker 
<https://bugs.python.org/issue33766>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com