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
52138792
Commit
52138792
authored
May 10, 2012
by
scoder
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #120 from vitek/_type_inference
Infer variable as pyobject when del-ed, fix #768
parents
a1dc8203
7cccaa06
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
6 deletions
+59
-6
Cython/Compiler/FlowControl.py
Cython/Compiler/FlowControl.py
+13
-0
Cython/Compiler/TypeInference.py
Cython/Compiler/TypeInference.py
+4
-4
tests/errors/w_uninitialized_del.pyx
tests/errors/w_uninitialized_del.pyx
+0
-2
tests/run/type_inference_T768.pyx
tests/run/type_inference_T768.pyx
+21
-0
tests/run/type_inference_T768_cpp.pyx
tests/run/type_inference_T768_cpp.pyx
+21
-0
No files found.
Cython/Compiler/FlowControl.py
View file @
52138792
...
...
@@ -313,6 +313,12 @@ class NameAssignment(object):
def
__repr__
(
self
):
return
'%s(entry=%r)'
%
(
self
.
__class__
.
__name__
,
self
.
entry
)
def
infer_type
(
self
,
scope
):
return
self
.
rhs
.
infer_type
(
scope
)
def
type_dependencies
(
self
,
scope
):
return
self
.
rhs
.
type_dependencies
(
scope
)
class
Argument
(
NameAssignment
):
def
__init__
(
self
,
lhs
,
rhs
,
entry
):
...
...
@@ -325,6 +331,13 @@ class NameDeletion(NameAssignment):
NameAssignment
.
__init__
(
self
,
lhs
,
lhs
,
entry
)
self
.
is_deletion
=
True
def
infer_type
(
self
,
scope
):
inferred_type
=
self
.
rhs
.
infer_type
(
scope
)
if
(
not
inferred_type
.
is_pyobject
and
inferred_type
.
can_coerce_to_pyobject
(
scope
)):
return
py_object_type
return
inferred_type
class
Uninitialized
(
object
):
pass
...
...
Cython/Compiler/TypeInference.py
View file @
52138792
...
...
@@ -363,7 +363,7 @@ class SimpleAssignmentTypeInferer(object):
continue
all
=
set
()
for
assmt
in
entry
.
cf_assignments
:
all
.
update
(
assmt
.
rhs
.
type_dependencies
(
scope
))
all
.
update
(
assmt
.
type_dependencies
(
scope
))
if
all
:
dependancies_by_entry
[
entry
]
=
all
for
dep
in
all
:
...
...
@@ -401,12 +401,12 @@ class SimpleAssignmentTypeInferer(object):
# Deal with simple circular dependancies...
for
entry
,
deps
in
dependancies_by_entry
.
items
():
if
len
(
deps
)
==
1
and
deps
==
set
([
entry
]):
types
=
[
assmt
.
rhs
.
infer_type
(
scope
)
types
=
[
assmt
.
infer_type
(
scope
)
for
assmt
in
entry
.
cf_assignments
if
assmt
.
rhs
.
type_dependencies
(
scope
)
==
()]
if
assmt
.
type_dependencies
(
scope
)
==
()]
if
types
:
entry
.
type
=
spanning_type
(
types
,
entry
.
might_overflow
)
types
=
[
assmt
.
rhs
.
infer_type
(
scope
)
types
=
[
assmt
.
infer_type
(
scope
)
for
assmt
in
entry
.
cf_assignments
]
entry
.
type
=
spanning_type
(
types
,
entry
.
might_overflow
)
# might be wider...
resolve_dependancy
(
entry
)
...
...
tests/errors/w_uninitialized_del.pyx
View file @
52138792
...
...
@@ -9,8 +9,6 @@ def foo(x):
return
a
,
b
_ERRORS
=
"""
7:9: Deletion of non-Python, non-C++ object
7:12: local variable 'b' referenced before assignment
7:12: Deletion of non-Python, non-C++ object
9:12: local variable 'a' referenced before assignment
"""
tests/run/type_inference_T768.pyx
0 → 100644
View file @
52138792
# mode: run
# ticket: 768
from
cython
cimport
typeof
def
type_inference_del_int
():
"""
>>> type_inference_del_int()
'Python object'
"""
x
=
1
del
x
return
typeof
(
x
)
def
type_inference_del_dict
():
"""
>>> type_inference_del_dict()
'dict object'
"""
x
=
{}
del
x
return
typeof
(
x
)
tests/run/type_inference_T768_cpp.pyx
0 → 100644
View file @
52138792
# mode: run
# tag: cpp
# ticket: 768
from
cython
cimport
typeof
cdef
extern
from
"shapes.h"
namespace
"shapes"
:
cdef
cppclass
Shape
:
float
area
()
cdef
cppclass
Circle
(
Shape
):
int
radius
Circle
(
int
)
def
type_inference_del_cpp
():
"""
>>> type_inference_del_cpp()
'Circle *'
"""
x
=
new
Circle
(
10
)
del
x
return
typeof
(
x
)
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