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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
45e1d7e0
Commit
45e1d7e0
authored
Jul 03, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow TreeFragments to substitute 'as' target names in 'from ... import ... as ...' statements
parent
bca614e2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
0 deletions
+16
-0
Cython/Compiler/Tests/TestTreeFragment.py
Cython/Compiler/Tests/TestTreeFragment.py
+9
-0
Cython/Compiler/TreeFragment.py
Cython/Compiler/TreeFragment.py
+7
-0
No files found.
Cython/Compiler/Tests/TestTreeFragment.py
View file @
45e1d7e0
...
...
@@ -178,6 +178,15 @@ class TestTreeFragments(CythonTest):
self
.
assertTrue
(
isinstance
(
T
.
stats
[
0
],
PropertyNode
),
T
)
self
.
assertTrue
(
T
.
stats
[
0
].
name
==
"test"
,
T
)
def
test_fromimportstatnode
(
self
):
F
=
TreeFragment
(
u"from A import b as NAME"
)
T
=
F
.
substitute
({
"NAME"
:
NameNode
(
None
,
name
=
"test"
),
})
self
.
assertTrue
(
isinstance
(
T
.
stats
[
0
],
FromImportStatNode
),
T
)
self
.
assertTrue
(
isinstance
(
T
.
stats
[
0
].
items
[
0
][
1
],
NameNode
),
T
)
self
.
assertTrue
(
T
.
stats
[
0
].
items
[
0
][
1
].
name
==
"test"
,
T
)
if
__name__
==
"__main__"
:
import
unittest
unittest
.
main
()
Cython/Compiler/TreeFragment.py
View file @
45e1d7e0
...
...
@@ -246,6 +246,13 @@ class TemplateTransform(VisitorTransform):
else
:
return
self
.
visit_Node
(
node
)
def
visit_FromImportStatNode
(
self
,
node
):
for
i
,
item
in
enumerate
(
node
.
items
):
name
,
target_namenode
=
item
new_namenode
=
self
.
visit
(
target_namenode
)
node
.
items
[
i
]
=
(
name
,
new_namenode
)
return
self
.
visit_Node
(
node
)
def
copy_code_tree
(
node
):
return
TreeCopier
()(
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