Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
094c9c92
Commit
094c9c92
authored
May 18, 2016
by
Berker Peksag
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #23275: Allow () = iterable assignment syntax
Documentation updates by Martin Panter.
parent
93d22ecc
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
41 additions
and
41 deletions
+41
-41
Doc/reference/simple_stmts.rst
Doc/reference/simple_stmts.rst
+15
-16
Lib/test/test_codeop.py
Lib/test/test_codeop.py
+0
-1
Lib/test/test_syntax.py
Lib/test/test_syntax.py
+0
-12
Lib/test/test_unpack.py
Lib/test/test_unpack.py
+21
-0
Lib/test/test_with.py
Lib/test/test_with.py
+0
-5
Misc/NEWS
Misc/NEWS
+3
-0
Python/ast.c
Python/ast.c
+2
-7
No files found.
Doc/reference/simple_stmts.rst
View file @
094c9c92
...
...
@@ -84,8 +84,8 @@ attributes or items of mutable objects:
assignment_stmt
:
(`
target_list
`
"="
)+
(`
expression_list
`
|
`
yield_expression
`)
target_list
:
`
target
`
(
","
`
target
`)*
[
","
]
target
:
`
identifier
`
:
|
"("
`
target_list
`
")"
:
|
"["
`
target_list
`
"]"
:
|
"("
[`
target_list
`]
")"
:
|
"["
[`
target_list
`]
"]"
:
|
`
attributeref
`
:
|
`
subscription
`
:
|
`
slicing
`
...
...
@@ -115,21 +115,25 @@ given with the definition of the object types (see section :ref:`types`).
Assignment
of
an
object
to
a
target
list
,
optionally
enclosed
in
parentheses
or
square
brackets
,
is
recursively
defined
as
follows
.
*
If
the
target
list
is
a
single
target
:
The
object
is
assigned
to
that
target
.
*
If
the
target
list
is
empty
:
The
object
must
also
be
an
empty
iterable
.
*
If
the
target
list
is
a
comma
-
separated
list
of
targets
:
The
object
must
be
an
iterable
with
the
same
number
of
items
as
there
are
targets
in
the
target
list
,
and
the
items
are
assigned
,
from
left
to
right
,
to
the
corresponding
targets
.
*
If
the
target
list
is
a
single
target
in
parentheses
:
The
object
is
assigned
to
that
target
.
*
If
the
target
list
is
a
comma
-
separated
list
of
targets
,
or
a
single
target
in
square
brackets
:
The
object
must
be
an
iterable
with
the
same
number
of
items
as
there
are
targets
in
the
target
list
,
and
the
items
are
assigned
,
from
left
to
right
,
to
the
corresponding
targets
.
*
If
the
target
list
contains
one
target
prefixed
with
an
asterisk
,
called
a
"starred"
target
:
The
object
must
be
a
sequenc
e
with
at
least
as
many
items
"starred"
target
:
The
object
must
be
a
n
iterabl
e
with
at
least
as
many
items
as
there
are
targets
in
the
target
list
,
minus
one
.
The
first
items
of
the
sequenc
e
are
assigned
,
from
left
to
right
,
to
the
targets
before
the
starred
target
.
The
final
items
of
the
sequenc
e
are
assigned
to
the
targets
after
the
starred
target
.
A
list
of
the
remaining
items
in
the
sequenc
e
is
then
iterabl
e
are
assigned
,
from
left
to
right
,
to
the
targets
before
the
starred
target
.
The
final
items
of
the
iterabl
e
are
assigned
to
the
targets
after
the
starred
target
.
A
list
of
the
remaining
items
in
the
iterabl
e
is
then
assigned
to
the
starred
target
(
the
list
can
be
empty
).
*
Else
:
The
object
must
be
a
sequenc
e
with
the
same
number
of
items
as
there
*
Else
:
The
object
must
be
a
n
iterabl
e
with
the
same
number
of
items
as
there
are
targets
in
the
target
list
,
and
the
items
are
assigned
,
from
left
to
right
,
to
the
corresponding
targets
.
...
...
@@ -150,11 +154,6 @@ Assignment of an object to a single target is recursively defined as follows.
count
for
the
object
previously
bound
to
the
name
to
reach
zero
,
causing
the
object
to
be
deallocated
and
its
destructor
(
if
it
has
one
)
to
be
called
.
*
If
the
target
is
a
target
list
enclosed
in
parentheses
or
in
square
brackets
:
The
object
must
be
an
iterable
with
the
same
number
of
items
as
there
are
targets
in
the
target
list
,
and
its
items
are
assigned
,
from
left
to
right
,
to
the
corresponding
targets
.
..
index
::
pair
:
attribute
;
assignment
*
If
the
target
is
an
attribute
reference
:
The
primary
expression
in
the
...
...
Lib/test/test_codeop.py
View file @
094c9c92
...
...
@@ -282,7 +282,6 @@ class CodeopTests(unittest.TestCase):
ai
(
"if (a == 1 and b = 2): pass"
)
ai
(
"del 1"
)
ai
(
"del ()"
)
ai
(
"del (1,)"
)
ai
(
"del [1]"
)
ai
(
"del '1'"
)
...
...
Lib/test/test_syntax.py
View file @
094c9c92
...
...
@@ -35,14 +35,6 @@ SyntaxError: invalid syntax
Traceback (most recent call last):
SyntaxError: can't assign to keyword
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):
SyntaxError: can't assign to ()
>>> f() = 1
Traceback (most recent call last):
SyntaxError: can't assign to function call
...
...
@@ -491,10 +483,6 @@ Traceback (most recent call last):
...
SyntaxError: keyword argument repeated
>>> del ()
Traceback (most recent call last):
SyntaxError: can't delete ()
>>> {1, 2, 3} = 42
Traceback (most recent call last):
SyntaxError: can't assign to literal
...
...
Lib/test/test_unpack.py
View file @
094c9c92
...
...
@@ -117,6 +117,27 @@ error)
...
test.test_unpack.BozoError
Allow unpacking empty iterables
>>> () = []
>>> [] = ()
>>> [] = []
>>> () = ()
Unpacking non-iterables should raise TypeError
>>> () = 42
Traceback (most recent call last):
...
TypeError: 'int' object is not iterable
Unpacking to an empty iterable should raise ValueError
>>> () = [42]
Traceback (most recent call last):
...
ValueError: too many values to unpack (expected 0)
"""
__test__
=
{
'doctests'
:
doctests
}
...
...
Lib/test/test_with.py
View file @
094c9c92
...
...
@@ -140,11 +140,6 @@ class FailureTestCase(unittest.TestCase):
'with mock as (None):
\
n
'
' pass'
)
def
testAssignmentToEmptyTupleError
(
self
):
self
.
assertRaisesSyntaxError
(
'with mock as ():
\
n
'
' pass'
)
def
testAssignmentToTupleOnlyContainingNoneError
(
self
):
self
.
assertRaisesSyntaxError
(
'with mock as None,:
\
n
pass'
)
self
.
assertRaisesSyntaxError
(
...
...
Misc/NEWS
View file @
094c9c92
...
...
@@ -22,6 +22,9 @@ Release date: 2016-05-16
Core
and
Builtins
-----------------
-
Issue
#
23275
:
Allow
assigning
to
an
empty
target
list
in
round
brackets
:
()
=
iterable
.
-
Issue
#
26991
:
Fix
possible
refleak
when
creating
a
function
with
annotations
.
-
Issue
#
27039
:
Fixed
bytearray
.
remove
()
for
values
greater
than
127.
Based
on
...
...
Python/ast.c
View file @
094c9c92
...
...
@@ -990,13 +990,8 @@ set_context(struct compiling *c, expr_ty e, expr_context_ty ctx, const node *n)
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
=
"()"
;
}
e
->
v
.
Tuple
.
ctx
=
ctx
;
s
=
e
->
v
.
Tuple
.
elts
;
break
;
case
Lambda_kind
:
expr_name
=
"lambda"
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment