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
Boxiang Sun
cython
Commits
b7a94dfd
Commit
b7a94dfd
authored
Apr 02, 2011
by
Haoyu Bai
Committed by
Robert Bradshaw
Apr 16, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add py2_import directive to control import level
parent
cf7ae767
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
16 deletions
+22
-16
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+7
-0
Cython/Compiler/Options.py
Cython/Compiler/Options.py
+1
-0
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+8
-15
tests/run/relativeimport_T542.pyx
tests/run/relativeimport_T542.pyx
+6
-1
No files found.
Cython/Compiler/ExprNodes.py
View file @
b7a94dfd
...
...
@@ -1749,12 +1749,19 @@ class ImportNode(ExprNode):
# 0: absolute import;
# >0: the number of parent directories to search
# relative to the current module.
# None: decide the level according to language level and
# directives
type
=
py_object_type
subexprs
=
[
'module_name'
,
'name_list'
]
def
analyse_types
(
self
,
env
):
if
self
.
level
is
None
:
if
env
.
directives
[
'language_level'
]
<
3
or
env
.
directives
[
'py2_import'
]:
self
.
level
=
-
1
else
:
self
.
level
=
0
self
.
module_name
.
analyse_types
(
env
)
self
.
module_name
=
self
.
module_name
.
coerce_to_pyobject
(
env
)
if
self
.
name_list
:
...
...
Cython/Compiler/Options.py
View file @
b7a94dfd
...
...
@@ -81,6 +81,7 @@ directive_defaults = {
'autotestdict.all'
:
False
,
'language_level'
:
2
,
'fast_getattr'
:
False
,
# Undocumented until we come up with a better way to handle this everywhere.
'py2_import'
:
False
,
# For backward compatibility of Cython's source code
'warn'
:
None
,
'warn.undeclared'
:
False
,
...
...
Cython/Compiler/Parsing.py
View file @
b7a94dfd
...
...
@@ -1189,11 +1189,6 @@ def p_raise_statement(s):
return
Nodes
.
ReraiseStatNode
(
pos
)
def
p_import_statement
(
s
):
# will do absolute import in Py3 and try both relative and absolute in Py2.
if
s
.
context
.
language_level
>=
3
:
level
=
0
else
:
level
=
-
1
# s.sy in ('import', 'cimport')
pos
=
s
.
position
()
kind
=
s
.
sy
...
...
@@ -1221,7 +1216,7 @@ def p_import_statement(s):
rhs
=
ExprNodes
.
ImportNode
(
pos
,
module_name
=
ExprNodes
.
IdentifierStringNode
(
pos
,
value
=
dotted_name
),
level
=
level
,
level
=
None
,
name_list
=
name_list
))
stats
.
append
(
stat
)
return
Nodes
.
StatListNode
(
pos
,
stats
=
stats
)
...
...
@@ -1236,18 +1231,16 @@ def p_from_import_statement(s, first_statement = 0):
while
s
.
sy
==
'.'
:
level
+=
1
s
.
next
()
else
:
# will do absolute import in Py3 and try both relative and absolute in Py2.
if
s
.
context
.
language_level
>=
3
:
level
=
0
else
:
level
=
-
1
if
level
>
0
and
s
.
sy
==
'cimport'
:
if
s
.
sy
==
'cimport'
:
s
.
error
(
"Relative cimport is not supported yet"
)
if
level
>
0
and
s
.
sy
==
'import'
:
else
:
level
=
None
if
level
is
not
None
and
s
.
sy
==
'import'
:
# we are dealing with "from .. import foo, bar"
dotted_name_pos
,
dotted_name
=
s
.
position
(),
''
elif
level
is
not
None
and
s
.
sy
==
'cimport'
:
# "from .. cimport"
s
.
error
(
"Relative cimport is not supported yet"
)
else
:
(
dotted_name_pos
,
_
,
dotted_name
,
_
)
=
\
p_dotted_name
(
s
,
as_allowed
=
0
)
...
...
tests/run/relativeimport_T542.pyx
View file @
b7a94dfd
# cython: language_level=3
__name__
=
'distutils.baregg'
# fool Python we are in distutils
import
sys
# fool Python we are in distutils
if
sys
.
version_info
>=
(
3
,):
__package__
=
'distutils'
else
:
__package__
=
b'distutils'
from
distutils
import
cmd
,
core
,
version
from
.core
import
*
...
...
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