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
0f122b6d
Commit
0f122b6d
authored
May 09, 2012
by
Vitja Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Infer variable as pyobject when del-ed, fix #768
parent
909f362c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
4 deletions
+59
-4
Cython/Compiler/FlowControl.py
Cython/Compiler/FlowControl.py
+13
-0
Cython/Compiler/TypeInference.py
Cython/Compiler/TypeInference.py
+4
-4
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 @
0f122b6d
...
...
@@ -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 @
0f122b6d
...
...
@@ -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/run/type_inference_T768.pyx
0 → 100644
View file @
0f122b6d
# 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 @
0f122b6d
# 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