# HG changeset patch # User Paul Boddie # Date 1530799293 -7200 # Node ID 2b30e05ae0d5ecc02632d3478faad61f1ad66cd5 # Parent 20667fb4b8cfc23e228fada75d4ca7e34684e3e7 Introduced the detection of a particular error before its effects cause a less helpful error later in the deduction process (involving the absence of accessor types). diff -r 20667fb4b8cf -r 2b30e05ae0d5 deducer.py --- a/deducer.py Thu Jul 05 16:00:24 2018 +0200 +++ b/deducer.py Thu Jul 05 16:01:33 2018 +0200 @@ -2136,6 +2136,17 @@ if constrained: self.accessor_constrained.add(location) + # Complain about situations where no types are valid but where a + # specific, known accessor type has been indicated. This absence of + # suitable types is likely to occur when the presence of invocations + # filters out the accessor type. + + if not class_only_types and not instance_types and not module_types and \ + invocations and constrained_specific: + + raise DeduceError("In %s, methods of class %s cannot be called directly." % + (path, name)) + def update_provider_types(self, location, class_types, instance_types, module_types): """ diff -r 20667fb4b8cf -r 2b30e05ae0d5 tests/contexts.py --- a/tests/contexts.py Thu Jul 05 16:00:24 2018 +0200 +++ b/tests/contexts.py Thu Jul 05 16:01:33 2018 +0200 @@ -5,6 +5,8 @@ self.x = x self.y = 3 self.z = "zebra libre" + def __len__(self): + return len(self.z) c = C([1]) x = c.x @@ -45,3 +47,11 @@ print b # zebra libre print i # __builtins__.str.basestring.__len__ print i() # 11 + +j = C.__len__ +k = get_using(j, c) +try: + print j() +except UnboundMethodInvocation: + print "j(): invocation of method with class context" +print k() # 11 diff -r 20667fb4b8cf -r 2b30e05ae0d5 tests/methods_unbound_bad.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/methods_unbound_bad.py Thu Jul 05 16:01:33 2018 +0200 @@ -0,0 +1,12 @@ +class C: + def __init__(self, x, y, z): + self.x = x + self.y = y + self.z = z + + def c(self): + return self.x + +c = C(1, 2, 3) +print c.c() # 1 +print C.c() # bad