Commit 6dd263aa authored by Robert Bradshaw's avatar Robert Bradshaw

Don't infer unbond function types for bound methods.

This fixes #551.
parent 5796b9b0
...@@ -6309,6 +6309,10 @@ class AttributeNode(ExprNode): ...@@ -6309,6 +6309,10 @@ class AttributeNode(ExprNode):
# builtin types cannot be inferred as C functions as # builtin types cannot be inferred as C functions as
# that would prevent their use as bound methods # that would prevent their use as bound methods
return py_object_type return py_object_type
elif self.entry and self.entry.is_cmethod:
# special case: bound methods should not be inferred
# as their unbound method types
return py_object_type
return self.type return self.type
def analyse_target_declaration(self, env): def analyse_target_declaration(self, env):
......
...@@ -722,3 +722,26 @@ cdef class InferInProperties: ...@@ -722,3 +722,26 @@ cdef class InferInProperties:
d = enum_y d = enum_y
c = d c = d
return typeof(a), typeof(b), typeof(c), typeof(d) return typeof(a), typeof(b), typeof(c), typeof(d)
cdef class WithMethods:
cdef int offset
def __init__(self, offset):
self.offset = offset
cpdef int one_arg(self, int x):
return x + self.offset
cpdef int default_arg(self, int x, int y=0):
return x + y + self.offset
def test_bound_methods():
"""
>>> test_bound_methods()
"""
o = WithMethods(10)
assert typeof(o) == 'WithMethods', typeof(o)
one_arg = o.one_arg
assert one_arg(2) == 12, one_arg(2)
default_arg = o.default_arg
assert default_arg(2) == 12, default_arg(2)
assert default_arg(2, 3) == 15, default_arg(2, 2)
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