[issue23275] Can assign [] = (), but not () = []

2016-06-08 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 39a72018dd76 by Martin Panter in branch '3.5':
Issue #23275: Backport target list assignment documentation fixes
https://hg.python.org/cpython/rev/39a72018dd76

New changeset 8700f4d09b28 by Martin Panter in branch '2.7':
Issue #23275: Backport empty square bracket assignment documentation fix
https://hg.python.org/cpython/rev/8700f4d09b28

--

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2016-05-18 Thread Martin Panter

Martin Panter added the comment:

I just moved the NEWS entry under the alpha 2 heading.

For patches I am going to commit myself, I usually write the NEWS beforehand 
and remember to adjust it when committing. But perhaps I shouldn’t have done 
that in this case :)

--

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2016-05-18 Thread Roundup Robot

Roundup Robot added the comment:

New changeset d3a75daf61e1 by Martin Panter in branch 'default':
Issue #23275: Don’t think this made it into alpha 1
https://hg.python.org/cpython/rev/d3a75daf61e1

--

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2016-05-17 Thread Berker Peksag

Berker Peksag added the comment:

Thanks Martin. Your edits look much better! :) I will be travelling for PyCon 
US later this week so I just committed issue23275_v4.diff with minor edits.

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2016-05-17 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 8a0754fed986 by Berker Peksag in branch 'default':
Issue #23275: Allow () = iterable assignment syntax
https://hg.python.org/cpython/rev/8a0754fed986

--
nosy: +python-dev

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2016-05-17 Thread Martin Panter

Martin Panter added the comment:

Hi Berker. I updated your patch according to my comments in the documentation. 
I hope you don’t mind.

I reverted all the changes about subscripting and slicing an iterable, since 
this bug is only about assigning to a “target list”.

Actually it is true (despite the current documentation) that you can often 
assign

sequence[slice] = iterable

But I think that is a separate problem.

--
Added file: http://bugs.python.org/file42878/issue23275_v4.diff

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2016-05-07 Thread Martin Panter

Martin Panter added the comment:

Erm, I think you went overboard with the sequence → iterable changes and 
subscripting; see the review. Also, I think target_list should be made optional 
in the grammar description.

--

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2016-05-04 Thread Berker Peksag

Berker Peksag added the comment:

Here is an updated patch. I moved the test into test_unpack and added 
additional tests. sequence -> iterable changes should probably be applied to 
3.5 as well.

Thanks for the review, Martin.

--
type: behavior -> enhancement
Added file: http://bugs.python.org/file42715/issue23275_v3.diff

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2016-04-26 Thread Martin Panter

Martin Panter added the comment:

Okay I’ll let Berker update his patch, but I’m happy to try my hand at updating 
the documentation if needed.

I reviewed the current patch. I can’t say whether the ast.c change is good or 
not. But IMO the test would be better off in somewhere like 
/Lib/test/test_unpack.py. It is only a superficial relationship with tuples 
because the syntax looks the same. Also may be worth testing that [] = [] etc 
work as well.

--

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2016-04-26 Thread Berker Peksag

Berker Peksag added the comment:

I missed Martin's comment about the documentation. I will update my patch.

--

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2016-04-26 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Martin, do you want to take it from here?

--
assignee: rhettinger -> martin.panter

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-07-06 Thread Martin Panter

Martin Panter added the comment:

I welcome this patch to go ahead. But the documentation 
 
also needs updating (see original post). I think it should mention that 
“target_list” can be empty. And it should use “iterable” instead of “sequence” 
in more places.

--

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-06-13 Thread Berker Peksag

Berker Peksag added the comment:

Thanks for the reviews. Here is an updated patch.

--
Added file: http://bugs.python.org/file39703/issue23275_v2.diff

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-05-27 Thread Stefan Behnel

Changes by Stefan Behnel :


--
nosy: +scoder

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-05-27 Thread Nick Coghlan

Nick Coghlan added the comment:

+1 for Martin's suggestion of removing the inconsistency the other way (i.e. 
allowing "() = iterable" to mean the same thing as "[] = iterable", effectively 
asserting that an iterable is empty)

I also agree with Raymond that it doesn't need to be mentioned in the What's 
New doc, just in the NEWS file.

--

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-05-27 Thread flying sheep

flying sheep added the comment:

> isn't it logical?
> 
> [] is a mutable data structure
> while () is a immutable data structure

but you don’t assign to data structures, but to names. you *modify* data 
structures. and in the square bracket assignment syntax you don’t modify the 
list created by the []. in fact the [] never even create a list.

—

also it’s news to me that [a, b] = range(2) works!

i always did a, b = range(2), and knew that (a, b) = range(2) works.

but assigning to something looking like a list literal is new and surprising to 
me. (and i thought i’ve mastered every corner of python’s syntax)

--
nosy: +flying sheep

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-05-27 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Berker's patch looks good.
It has several virtues:

* the error message is reasonable and clear
* it makes the language more consistent
* it doesn't break any existing code.
* it makes the AST a little simpler and faster
  by removing a special case

The patch needs to updated:
* remove the whatsnew entry
* fix test_codeop which expects "del ()" to raise SyntaxError
* fix test_syntax which fails on "() = 1" and "del ()"
* fix test_with which fails on "with mock as ()"

--
assignee:  -> rhettinger
versions: +Python 3.6 -Python 3.5

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-05-27 Thread Martin Panter

Martin Panter added the comment:

I prefer to unpack into square brackets in general because it is a mnemonic for 
the star argument being a list:

>>> (a, *b) = range(3)
>>> a
0
>>> b  # A list, even though it was unpacked using tuple-like syntax
[1, 2]

--

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-05-27 Thread Devin Jeanpierre

Devin Jeanpierre added the comment:

[a, b] = (1, 2) is also fine.

--

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-05-27 Thread Rahul Gupta

Rahul Gupta added the comment:

isn't it logical?

[] is a mutable data structure
while () is a immutable data structure

(b, a) = [1, 2] is fine because a and b are mutable

--
nosy: +Rahul Gupta

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-05-27 Thread Ionel Cristian Mărieș

Changes by Ionel Cristian Mărieș :


--
nosy: +ionelmc

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-04-22 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc added the comment:

About the patch: I'm sure there are other tests to change,
in test_syntax.py for example::

It's a syntax error to assign to the empty tuple.  Why isn't it an
error to assign to the empty list?  It will always raise some error  at
runtime.

>>> () = 1
Traceback (most recent call last):
  File "", line 1
SyntaxError: can't assign to ()

--
nosy: +amaury.forgeotdarc

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-04-22 Thread Berker Peksag

Berker Peksag added the comment:

I don't have a strong opinion on this, but here is a patch to make () = [] a 
valid assignment.

--
keywords: +patch
nosy: +berker.peksag
stage:  -> patch review
versions: +Python 3.5
Added file: http://bugs.python.org/file39165/issue23275.diff

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-04-20 Thread Mark Dickinson

Mark Dickinson added the comment:

> There is also no reason to break currently working code

Agreed.  To take one example, David Beazley's PyCon 2015 talk would have been 
broken by the suggested change!  (See 
https://www.youtube.com/watch?v=MCs5OvhV9S4, at around the 42:17 mark.)

If there's any code change resulting from this issue, I also think it should be 
to make assignment to `()` legal.

--
nosy: +mark.dickinson

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-04-19 Thread R. David Murray

R. David Murray added the comment:

There is also no reason to break currently working code, which turning this 
into a syntax error would od.

--

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-04-18 Thread Martin Panter

Martin Panter added the comment:

I would prefer this be fixed in the opposite direction, to allow “unpacking” an 
empty iterable using round brackets. I have used this syntax on purpose as a 
concise way to ensure that a generator is exhaused with no more yields:

>>> def gen():
... yield "partial computation"
... print("computation allowed to complete")
... 
>>> g = gen()
>>> next(g)
'partial computation'
>>> [] = g
computation allowed to complete

--

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-04-18 Thread Nick Coghlan

Nick Coghlan added the comment:

As Raymond notes, this is a fairly harmless quirk - it changes a SyntaxError to 
an iterable length dependent ValueError:

>>> () = []
  File "", line 1
SyntaxError: can't assign to ()
>>> [] = ()
>>> [] = [1]
Traceback (most recent call last):
  File "", line 1, in 
ValueError: too many values to unpack (expected 0)

I only found out about this after being puzzled when a typo in a live demo at 
PyCon 2015 failed to fail as I expected after seeing the presenter type a "[]" 
into the LHS of an assignment instead of the intended "_".

Removing the data dependence to make the assignment fail immediately (even if 
never tested against a non-empty iterable) would involve making the handling of 
List_kind match that of Tuple_kind in the switch statement that eryksun quoted.

I don't think it's an urgent fix, but if someone wanted to fix it (including a 
new test), I think it would be a reasonable contribution to accept.

--
nosy: +ncoghlan

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-03-02 Thread Ezio Melotti

Changes by Ezio Melotti :


--
nosy: +ezio.melotti

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-01-20 Thread eryksun

eryksun added the comment:

In ast.c, set_context checks for assignment to an empty tuple, but not an empty 
list.

case List_kind:
e->v.List.ctx = ctx;
s = e->v.List.elts;
break;
case Tuple_kind:
if (asdl_seq_LEN(e->v.Tuple.elts))  {
e->v.Tuple.ctx = ctx;
s = e->v.Tuple.elts;
}
else {
expr_name = "()";
}
break;

https://hg.python.org/cpython/file/ab2c023a9432/Python/ast.c#l912

--
nosy: +eryksun

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-01-20 Thread Martin Panter

Martin Panter added the comment:

But () is the odd one out if you consider

>>> [a, b] = range(2)
>>> [] = range(0)
>>> (a, b) = range(2)
>>> () = range(0)
  File "", line 1
SyntaxError: can't assign to ()

--
nosy: +vadmium

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-01-20 Thread Kyle Buzsaki

Kyle Buzsaki added the comment:

It seems that assigning to [] is the odd one out in this case. Why is this even 
possible?

>>> [] = ()
>>> [] = {}
>>> [] = set()
>>> list() = ()
  File "", line 1
SyntaxError: can't assign to function call
>>> () = []
  File "", line 1
SyntaxError: can't assign to ()
>>> {} = []
  File "", line 1
SyntaxError: can't assign to literal
>>> set() = []
  File "", line 1
SyntaxError: can't assign to function call
>>>

--
nosy: +Kyle.Buzsaki

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-01-19 Thread Raymond Hettinger

Raymond Hettinger added the comment:

The starting point is recognizing that this has been around for very long time 
and is harmless.

--
nosy: +rhettinger

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-01-19 Thread R. David Murray

R. David Murray added the comment:

My guess is that it is not worth complicating the parser in order to make these 
two cases consistent, and it should be treated as a doc error.  We'll see what 
other developers think.

--
nosy: +r.david.murray

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-01-19 Thread Cesar Kawakami

Changes by Cesar Kawakami :


--
nosy: +Cesar.Kawakami

___
Python tracker 

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



[issue23275] Can assign [] = (), but not () = []

2015-01-19 Thread Devin Jeanpierre

New submission from Devin Jeanpierre:

>>> [] = ()
>>> () = []
  File "", line 1
SyntaxError: can't assign to ()

This contradicts the assignment grammar, which would make both illegal: 
https://docs.python.org/3/reference/simple_stmts.html#assignment-statements

--
components: Interpreter Core
messages: 234324
nosy: Devin Jeanpierre
priority: normal
severity: normal
status: open
title: Can assign [] = (), but not () = []
type: behavior

___
Python tracker 

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