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
1565d164
Commit
1565d164
authored
Feb 09, 2010
by
Craig Citro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix trac #505: problem with cimport cython
parent
269519a8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
35 deletions
+24
-35
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+3
-1
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+21
-34
No files found.
Cython/Compiler/Nodes.py
View file @
1565d164
...
@@ -4873,7 +4873,9 @@ class FromImportStatNode(StatNode):
...
@@ -4873,7 +4873,9 @@ class FromImportStatNode(StatNode):
break
break
else
:
else
:
entry
=
env
.
lookup
(
target
.
name
)
entry
=
env
.
lookup
(
target
.
name
)
if
entry
.
is_type
and
entry
.
type
.
name
==
name
and
entry
.
type
.
module_name
==
self
.
module
.
module_name
.
value
:
if
(
entry
.
is_type
and
entry
.
type
.
name
==
name
and
entry
.
type
.
module_name
==
self
.
module
.
module_name
.
value
):
continue
# already cimported
continue
# already cimported
target
.
analyse_target_expression
(
env
,
None
)
target
.
analyse_target_expression
(
env
,
None
)
if
target
.
type
is
py_object_type
:
if
target
.
type
is
py_object_type
:
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
1565d164
...
@@ -337,8 +337,9 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
...
@@ -337,8 +337,9 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
'address'
:
AmpersandNode
,
'address'
:
AmpersandNode
,
}
}
special_methods
=
set
([
'declare'
,
'union'
,
'struct'
,
'typedef'
,
'sizeof'
,
'cast'
,
'pointer'
,
'compiled'
,
'NULL'
]
special_methods
=
set
([
'declare'
,
'union'
,
'struct'
,
'typedef'
,
'sizeof'
,
+
unop_method_nodes
.
keys
())
'cast'
,
'pointer'
,
'compiled'
,
'NULL'
]
+
unop_method_nodes
.
keys
())
def
__init__
(
self
,
context
,
compilation_directive_defaults
):
def
__init__
(
self
,
context
,
compilation_directive_defaults
):
super
(
InterpretCompilerDirectives
,
self
).
__init__
(
context
)
super
(
InterpretCompilerDirectives
,
self
).
__init__
(
context
)
...
@@ -373,38 +374,33 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
...
@@ -373,38 +374,33 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
node
.
cython_module_names
=
self
.
cython_module_names
node
.
cython_module_names
=
self
.
cython_module_names
return
node
return
node
# Track cimports of the cython module.
# The following four functions track imports and cimports that
# begin with "cython"
def
is_cython_directive
(
self
,
name
):
return
(
name
in
Options
.
directive_types
or
name
in
self
.
special_methods
or
PyrexTypes
.
parse_basic_type
(
name
))
def
visit_CImportStatNode
(
self
,
node
):
def
visit_CImportStatNode
(
self
,
node
):
if
node
.
module_name
==
u"cython"
:
if
node
.
module_name
==
u"cython"
:
if
node
.
as_name
:
self
.
cython_module_names
.
add
(
node
.
as_name
or
u"cython"
)
modname
=
node
.
as_name
else
:
modname
=
u"cython"
self
.
cython_module_names
.
add
(
modname
)
elif
node
.
module_name
.
startswith
(
u"cython."
):
elif
node
.
module_name
.
startswith
(
u"cython."
):
if
node
.
as_name
:
if
node
.
as_name
:
self
.
directive_names
[
node
.
as_name
]
=
node
.
module_name
[
7
:]
self
.
directive_names
[
node
.
as_name
]
=
node
.
module_name
[
7
:]
else
:
else
:
self
.
cython_module_names
.
add
(
u"cython"
)
self
.
cython_module_names
.
add
(
u"cython"
)
else
:
# if this cimport was a compiler directive, we don't
return
node
# want to leave the cimport node sitting in the tree
return
None
return
node
def
visit_FromCImportStatNode
(
self
,
node
):
def
visit_FromCImportStatNode
(
self
,
node
):
if
node
.
module_name
.
startswith
(
u"cython."
):
if
node
.
module_name
.
startswith
(
u"cython"
):
is_cython_module
=
True
submodule
=
(
node
.
module_name
+
u"."
)[
7
:]
submodule
=
node
.
module_name
[
7
:]
+
u"."
elif
node
.
module_name
==
u"cython"
:
is_cython_module
=
True
submodule
=
u""
else
:
is_cython_module
=
False
if
is_cython_module
:
newimp
=
[]
newimp
=
[]
for
pos
,
name
,
as_name
,
kind
in
node
.
imported_names
:
for
pos
,
name
,
as_name
,
kind
in
node
.
imported_names
:
full_name
=
submodule
+
name
full_name
=
submodule
+
name
if
(
full_name
in
Options
.
directive_types
or
if
self
.
is_cython_directive
(
full_name
):
full_name
in
self
.
special_methods
or
PyrexTypes
.
parse_basic_type
(
full_name
)):
if
as_name
is
None
:
if
as_name
is
None
:
as_name
=
full_name
as_name
=
full_name
self
.
directive_names
[
as_name
]
=
full_name
self
.
directive_names
[
as_name
]
=
full_name
...
@@ -419,21 +415,12 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
...
@@ -419,21 +415,12 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
return
node
return
node
def
visit_FromImportStatNode
(
self
,
node
):
def
visit_FromImportStatNode
(
self
,
node
):
if
node
.
module
.
module_name
.
value
.
startswith
(
u"cython."
):
if
node
.
module
.
module_name
.
value
.
startswith
(
u"cython"
):
is_cython_module
=
True
submodule
=
(
node
.
module
.
module_name
.
value
+
u"."
)[
7
:]
submodule
=
node
.
module
.
module_name
.
value
[
7
:]
+
u"."
elif
node
.
module
.
module_name
.
value
==
u"cython"
:
is_cython_module
=
True
submodule
=
u""
else
:
is_cython_module
=
False
if
is_cython_module
:
newimp
=
[]
newimp
=
[]
for
name
,
name_node
in
node
.
items
:
for
name
,
name_node
in
node
.
items
:
full_name
=
submodule
+
name
full_name
=
submodule
+
name
if
(
full_name
in
Options
.
directive_types
or
if
self
.
is_cython_directive
(
full_name
):
full_name
in
self
.
special_methods
or
PyrexTypes
.
parse_basic_type
(
full_name
)):
self
.
directive_names
[
name_node
.
name
]
=
full_name
self
.
directive_names
[
name_node
.
name
]
=
full_name
else
:
else
:
newimp
.
append
((
name
,
name_node
))
newimp
.
append
((
name
,
name_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