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
5e001476
Commit
5e001476
authored
May 27, 2008
by
Dag Sverre Seljebotn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TreeFragment fix: Replace enclosing ExprStatNode if statement is substituted
parent
bddf62c2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
0 deletions
+15
-0
Cython/Compiler/Tests/TestTreeFragment.py
Cython/Compiler/Tests/TestTreeFragment.py
+7
-0
Cython/Compiler/TreeFragment.py
Cython/Compiler/TreeFragment.py
+8
-0
No files found.
Cython/Compiler/Tests/TestTreeFragment.py
View file @
5e001476
from
Cython.TestUtils
import
CythonTest
from
Cython.Compiler.TreeFragment
import
*
from
Cython.Compiler.Nodes
import
*
class
TestTreeFragments
(
CythonTest
):
def
test_basic
(
self
):
...
...
@@ -21,6 +22,12 @@ class TestTreeFragments(CythonTest):
T
=
F
.
substitute
({
"x"
:
y
})
self
.
assertCode
(
u"y = 4"
,
T
)
def
test_exprstat
(
self
):
F
=
self
.
fragment
(
u"PASS"
)
pass_stat
=
PassStatNode
(
pos
=
None
)
T
=
F
.
substitute
({
"PASS"
:
pass_stat
})
self
.
assert_
(
T
.
body
is
pass_stat
,
T
.
body
)
if
__name__
==
"__main__"
:
import
unittest
unittest
.
main
()
Cython/Compiler/TreeFragment.py
View file @
5e001476
...
...
@@ -83,6 +83,14 @@ class SubstitutionTransform(VisitorTransform):
# Clone
return
self
.
visit_Node
(
node
)
def
visit_ExprStatNode
(
self
,
node
):
# If an expression-as-statement consists of only a replaceable
# NameNode, we replace the entire statement, not only the NameNode
if
isinstance
(
node
.
expr
,
NameNode
)
and
node
.
expr
.
name
in
self
.
substitute
:
return
self
.
substitute
[
node
.
expr
.
name
]
else
:
return
self
.
visit_Node
(
node
)
def
__call__
(
self
,
node
,
substitute
):
self
.
substitute
=
substitute
return
super
(
SubstitutionTransform
,
self
).
__call__
(
node
)
...
...
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