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
e884efb9
Commit
e884efb9
authored
Nov 05, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prevent absolute cimports from trying relative imports
parent
6528682e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
17 deletions
+27
-17
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+6
-1
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+21
-16
No files found.
Cython/Compiler/Nodes.py
View file @
e884efb9
...
...
@@ -7087,6 +7087,7 @@ class EnsureGILNode(GILExitNode):
def
generate_execution_code
(
self
,
code
):
code
.
put_ensure_gil
(
declare_gilstate
=
False
)
utility_code_for_cimports
=
{
# utility code (or inlining c) in a pxd (or pyx) file.
# TODO: Consider a generic user-level mechanism for importing
...
...
@@ -7094,19 +7095,23 @@ utility_code_for_cimports = {
'cpython.array.array'
:
(
"ArrayAPI"
,
"arrayarray.h"
),
}
class
CImportStatNode
(
StatNode
):
# cimport statement
#
# module_name string Qualified name of module being imported
# as_name string or None Name specified in "as" clause, if any
# is_absolute bool True for absolute imports, False otherwise
child_attrs
=
[]
is_absolute
=
False
def
analyse_declarations
(
self
,
env
):
if
not
env
.
is_module_scope
:
error
(
self
.
pos
,
"cimport only allowed at module level"
)
return
module_scope
=
env
.
find_module
(
self
.
module_name
,
self
.
pos
)
module_scope
=
env
.
find_module
(
self
.
module_name
,
self
.
pos
,
relative_level
=
0
if
self
.
is_absolute
else
-
1
)
if
"."
in
self
.
module_name
:
names
=
[
EncodedString
(
name
)
for
name
in
self
.
module_name
.
split
(
"."
)]
top_name
=
names
[
0
]
...
...
Cython/Compiler/Parsing.py
View file @
e884efb9
...
...
@@ -1279,38 +1279,43 @@ def p_raise_statement(s):
else
:
return
Nodes
.
ReraiseStatNode
(
pos
)
def
p_import_statement
(
s
):
# s.sy in ('import', 'cimport')
pos
=
s
.
position
()
kind
=
s
.
sy
s
.
next
()
items
=
[
p_dotted_name
(
s
,
as_allowed
=
1
)]
items
=
[
p_dotted_name
(
s
,
as_allowed
=
1
)]
while
s
.
sy
==
','
:
s
.
next
()
items
.
append
(
p_dotted_name
(
s
,
as_allowed
=
1
))
items
.
append
(
p_dotted_name
(
s
,
as_allowed
=
1
))
stats
=
[]
is_absolute
=
Future
.
absolute_import
in
s
.
context
.
future_directives
for
pos
,
target_name
,
dotted_name
,
as_name
in
items
:
dotted_name
=
EncodedString
(
dotted_name
)
if
kind
==
'cimport'
:
stat
=
Nodes
.
CImportStatNode
(
pos
,
module_name
=
dotted_name
,
as_name
=
as_name
)
stat
=
Nodes
.
CImportStatNode
(
pos
,
module_name
=
dotted_name
,
as_name
=
as_name
,
is_absolute
=
is_absolute
)
else
:
if
as_name
and
"."
in
dotted_name
:
name_list
=
ExprNodes
.
ListNode
(
pos
,
args
=
[
ExprNodes
.
IdentifierStringNode
(
pos
,
value
=
EncodedString
(
"*"
))])
name_list
=
ExprNodes
.
ListNode
(
pos
,
args
=
[
ExprNodes
.
IdentifierStringNode
(
pos
,
value
=
EncodedString
(
"*"
))])
else
:
name_list
=
None
stat
=
Nodes
.
SingleAssignmentNode
(
pos
,
lhs
=
ExprNodes
.
NameNode
(
pos
,
name
=
as_name
or
target_name
),
rhs
=
ExprNodes
.
ImportNode
(
pos
,
module_name
=
ExprNodes
.
IdentifierStringNode
(
pos
,
value
=
dotted_name
),
level
=
None
,
name_list
=
name_list
))
stat
=
Nodes
.
SingleAssignmentNode
(
pos
,
lhs
=
ExprNodes
.
NameNode
(
pos
,
name
=
as_name
or
target_name
),
rhs
=
ExprNodes
.
ImportNode
(
pos
,
module_name
=
ExprNodes
.
IdentifierStringNode
(
pos
,
value
=
dotted_name
),
level
=
0
if
is_absolute
else
None
,
name_list
=
name_list
))
stats
.
append
(
stat
)
return
Nodes
.
StatListNode
(
pos
,
stats
=
stats
)
return
Nodes
.
StatListNode
(
pos
,
stats
=
stats
)
def
p_from_import_statement
(
s
,
first_statement
=
0
):
# s.sy == 'from'
...
...
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