Commit f8284d55 authored by Robert Bradshaw's avatar Robert Bradshaw

Revert "Revert "Fix type inferance for constructors with keyword arguments.""

This reverts commit 21897347.

Turns out CPython broke on us at the same time this change was made.
parent 1c50b97d
...@@ -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':
......
...@@ -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():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment