1.1 --- a/deducer.py Thu Jul 05 16:00:24 2018 +0200
1.2 +++ b/deducer.py Thu Jul 05 16:01:33 2018 +0200
1.3 @@ -2136,6 +2136,17 @@
1.4 if constrained:
1.5 self.accessor_constrained.add(location)
1.6
1.7 + # Complain about situations where no types are valid but where a
1.8 + # specific, known accessor type has been indicated. This absence of
1.9 + # suitable types is likely to occur when the presence of invocations
1.10 + # filters out the accessor type.
1.11 +
1.12 + if not class_only_types and not instance_types and not module_types and \
1.13 + invocations and constrained_specific:
1.14 +
1.15 + raise DeduceError("In %s, methods of class %s cannot be called directly." %
1.16 + (path, name))
1.17 +
1.18 def update_provider_types(self, location, class_types, instance_types, module_types):
1.19
1.20 """
2.1 --- a/tests/contexts.py Thu Jul 05 16:00:24 2018 +0200
2.2 +++ b/tests/contexts.py Thu Jul 05 16:01:33 2018 +0200
2.3 @@ -5,6 +5,8 @@
2.4 self.x = x
2.5 self.y = 3
2.6 self.z = "zebra libre"
2.7 + def __len__(self):
2.8 + return len(self.z)
2.9
2.10 c = C([1])
2.11 x = c.x
2.12 @@ -45,3 +47,11 @@
2.13 print b # zebra libre
2.14 print i # __builtins__.str.basestring.__len__
2.15 print i() # 11
2.16 +
2.17 +j = C.__len__
2.18 +k = get_using(j, c)
2.19 +try:
2.20 + print j()
2.21 +except UnboundMethodInvocation:
2.22 + print "j(): invocation of method with class context"
2.23 +print k() # 11
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/tests/methods_unbound_bad.py Thu Jul 05 16:01:33 2018 +0200
3.3 @@ -0,0 +1,12 @@
3.4 +class C:
3.5 + def __init__(self, x, y, z):
3.6 + self.x = x
3.7 + self.y = y
3.8 + self.z = z
3.9 +
3.10 + def c(self):
3.11 + return self.x
3.12 +
3.13 +c = C(1, 2, 3)
3.14 +print c.c() # 1
3.15 +print C.c() # bad