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
b50c6792
Commit
b50c6792
authored
Oct 06, 2011
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix type inferance for constructors with keyword arguments.
parent
a6117482
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
21 deletions
+33
-21
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+21
-21
tests/run/type_inference.pyx
tests/run/type_inference.pyx
+12
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
b50c6792
...
@@ -3232,6 +3232,27 @@ class CallNode(ExprNode):
...
@@ -3232,6 +3232,27 @@ class CallNode(ExprNode):
# allow overriding the default 'may_be_none' behaviour
# allow overriding the default 'may_be_none' behaviour
may_return_none
=
None
may_return_none
=
None
def
infer_type
(
self
,
env
):
function
=
self
.
function
func_type
=
function
.
infer_type
(
env
)
if
isinstance
(
self
.
function
,
NewExprNode
):
return
PyrexTypes
.
CPtrType
(
self
.
function
.
class_type
)
if
func_type
.
is_ptr
:
func_type
=
func_type
.
base_type
if
func_type
.
is_cfunction
:
return
func_type
.
return_type
elif
func_type
is
type_type
:
if
function
.
is_name
and
function
.
entry
and
function
.
entry
.
type
:
result_type
=
function
.
entry
.
type
if
result_type
.
is_extension_type
:
return
result_type
elif
result_type
.
is_builtin_type
:
if
function
.
entry
.
name
==
'float'
:
return
PyrexTypes
.
c_double_type
elif
function
.
entry
.
name
in
Builtin
.
types_that_construct_their_instance
:
return
result_type
return
py_object_type
def
may_be_none
(
self
):
def
may_be_none
(
self
):
if
self
.
may_return_none
is
not
None
:
if
self
.
may_return_none
is
not
None
:
return
self
.
may_return_none
return
self
.
may_return_none
...
@@ -3309,27 +3330,6 @@ class SimpleCallNode(CallNode):
...
@@ -3309,27 +3330,6 @@ class SimpleCallNode(CallNode):
# the case of function overloading.
# the case of function overloading.
return
self
.
function
.
type_dependencies
(
env
)
return
self
.
function
.
type_dependencies
(
env
)
def
infer_type
(
self
,
env
):
function
=
self
.
function
func_type
=
function
.
infer_type
(
env
)
if
isinstance
(
self
.
function
,
NewExprNode
):
return
PyrexTypes
.
CPtrType
(
self
.
function
.
class_type
)
if
func_type
.
is_ptr
:
func_type
=
func_type
.
base_type
if
func_type
.
is_cfunction
:
return
func_type
.
return_type
elif
func_type
is
type_type
:
if
function
.
is_name
and
function
.
entry
and
function
.
entry
.
type
:
result_type
=
function
.
entry
.
type
if
result_type
.
is_extension_type
:
return
result_type
elif
result_type
.
is_builtin_type
:
if
function
.
entry
.
name
==
'float'
:
return
PyrexTypes
.
c_double_type
elif
function
.
entry
.
name
in
Builtin
.
types_that_construct_their_instance
:
return
result_type
return
py_object_type
def
analyse_as_type
(
self
,
env
):
def
analyse_as_type
(
self
,
env
):
attr
=
self
.
function
.
as_cython_attribute
()
attr
=
self
.
function
.
as_cython_attribute
()
if
attr
==
'pointer'
:
if
attr
==
'pointer'
:
...
...
tests/run/type_inference.pyx
View file @
b50c6792
...
@@ -513,6 +513,18 @@ def common_extension_type_base():
...
@@ -513,6 +513,18 @@ def common_extension_type_base():
w
=
CC
()
w
=
CC
()
assert
typeof
(
w
)
==
"Python object"
,
typeof
(
w
)
assert
typeof
(
w
)
==
"Python object"
,
typeof
(
w
)
cdef
class
AcceptsKeywords
:
def
__init__
(
self
,
*
args
,
**
kwds
):
pass
@
infer_types
(
None
)
def
constructor_call
():
"""
>>> constructor_call()
"""
x
=
AcceptsKeywords
(
a
=
1
,
b
=
2
)
assert
typeof
(
x
)
==
"AcceptsKeywords"
,
typeof
(
x
)
@
infer_types
(
None
)
@
infer_types
(
None
)
def
large_literals
():
def
large_literals
():
...
...
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