Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
64c5b254
Commit
64c5b254
authored
Feb 09, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement tuple compatibility form of Py2 exec statement
parent
0b2d3508
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
2 deletions
+58
-2
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+16
-2
tests/errors/exec_errors.pyx
tests/errors/exec_errors.pyx
+24
-0
tests/run/exectest.pyx
tests/run/exectest.pyx
+18
-0
No files found.
Cython/Compiler/Parsing.py
View file @
64c5b254
...
...
@@ -1157,14 +1157,28 @@ def p_exec_statement(s):
# s.sy == 'exec'
pos
=
s
.
position
()
s
.
next
()
args
=
[
p_bit_expr
(
s
)
]
code
=
p_bit_expr
(
s
)
if
isinstance
(
code
,
ExprNodes
.
TupleNode
):
# Py3 compatibility syntax
tuple_variant
=
True
args
=
code
.
args
if
len
(
args
)
not
in
(
2
,
3
):
s
.
error
(
"expected tuple of length 2 or 3, got length %d"
%
len
(
args
),
pos
=
pos
,
fatal
=
False
)
args
=
[
code
]
else
:
tuple_variant
=
False
args
=
[
code
]
if
s
.
sy
==
'in'
:
if
tuple_variant
:
s
.
error
(
"tuple variant of exec does not support additional 'in' arguments"
,
fatal
=
False
)
s
.
next
()
args
.
append
(
p_test
(
s
))
if
s
.
sy
==
','
:
s
.
next
()
args
.
append
(
p_test
(
s
))
return
Nodes
.
ExecStatNode
(
pos
,
args
=
args
)
return
Nodes
.
ExecStatNode
(
pos
,
args
=
args
)
def
p_del_statement
(
s
):
# s.sy == 'del'
...
...
tests/errors/exec_errors.pyx
0 → 100644
View file @
64c5b254
# mode: error
# tag: exec
def
test_exec_tuples
():
exec
()
exec
(
1
,)
exec
(
1
,
2
,
3
,
4
)
def
test_exec_tuples_with_in
(
d1
,
d2
):
exec
(
1
,
2
)
in
d1
exec
(
1
,
2
,
3
)
in
d1
exec
(
1
,
2
)
in
d1
,
d2
exec
(
1
,
2
,
3
)
in
d1
,
d2
_ERRORS
=
"""
5:4: expected tuple of length 2 or 3, got length 0
6:4: expected tuple of length 2 or 3, got length 1
7:4: expected tuple of length 2 or 3, got length 4
10:14: tuple variant of exec does not support additional 'in' arguments
11:16: tuple variant of exec does not support additional 'in' arguments
12:14: tuple variant of exec does not support additional 'in' arguments
13:16: tuple variant of exec does not support additional 'in' arguments
"""
tests/run/exectest.pyx
View file @
64c5b254
...
...
@@ -86,6 +86,24 @@ def test_dict_scope3(d1, d2):
def
test_dict_scope_ref
(
d1
,
d2
):
exec
u"b=a+c"
in
d1
,
d2
def
test_dict_scope_tuple2
():
"""
>>> test_dict_scope_tuple2()
2
"""
cdef
dict
d
=
{}
exec
(
u"b=1+1"
,
d
)
# Py3 compatibility syntax
return
d
[
u'b'
]
def
test_dict_scope_tuple3
(
d1
,
d2
):
"""
>>> d1, d2 = {}, {}
>>> test_dict_scope_tuple3(d1, d2)
>>> (d1.get('b'), d2.get('b'))
(None, 2)
"""
exec
(
u"b=1+1"
,
d1
,
d2
)
def
test_def
(
d
,
varref
):
exec
u"""
def test():
...
...
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