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
dfcca8d8
Commit
dfcca8d8
authored
Feb 12, 2010
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Infer common basetype for extension types.
parent
9ecd742d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
0 deletions
+44
-0
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+11
-0
tests/run/type_inference.pyx
tests/run/type_inference.pyx
+33
-0
No files found.
Cython/Compiler/PyrexTypes.py
View file @
dfcca8d8
...
...
@@ -2366,6 +2366,17 @@ def spanning_type(type1, type2):
return
widest_numeric_type
(
type1
,
c_double_type
)
elif
type1
.
is_pyobject
^
type2
.
is_pyobject
:
return
py_object_type
elif
type1
.
is_extension_type
and
type2
.
is_extension_type
:
if
type1
.
typeobj_is_imported
()
or
type2
.
typeobj_is_imported
():
return
py_object_type
while
True
:
if
type1
.
subtype_of
(
type2
):
return
type2
elif
type2
.
subtype_of
(
type1
):
return
type1
type1
,
type2
=
type1
.
base_type
,
type2
.
base_type
if
type1
is
None
or
type2
is
None
:
return
py_object_type
elif
type1
.
assignable_from
(
type2
):
if
type1
.
is_extension_type
and
type1
.
typeobj_is_imported
():
# external types are unsafe, so we use PyObject instead
...
...
tests/run/type_inference.pyx
View file @
dfcca8d8
...
...
@@ -304,3 +304,36 @@ def args_tuple_keywords_reassign_pyobjects(*args, **kwargs):
args
=
[]
kwargs
=
"test"
# / A -> AA -> AAA
# Base0 -> Base -
# \ B -> BB
# C -> CC
cdef
class
Base0
:
pass
cdef
class
Base
(
Base0
):
pass
cdef
class
A
(
Base
):
pass
cdef
class
AA
(
A
):
pass
cdef
class
AAA
(
AA
):
pass
cdef
class
B
(
Base
):
pass
cdef
class
BB
(
B
):
pass
cdef
class
C
:
pass
cdef
class
CC
(
C
):
pass
@
infer_types
(
None
)
def
common_extension_type_base
():
"""
>>> common_extension_type_base()
"""
x
=
A
()
x
=
AA
()
assert
typeof
(
x
)
==
"A"
,
typeof
(
x
)
y
=
A
()
y
=
B
()
assert
typeof
(
y
)
==
"Base"
,
typeof
(
y
)
z
=
AAA
()
z
=
BB
()
assert
typeof
(
z
)
==
"Base"
,
typeof
(
z
)
w
=
A
()
w
=
CC
()
assert
typeof
(
w
)
==
"Python object"
,
typeof
(
w
)
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