# HG changeset patch # User Paul Boddie # Date 1475250053 -7200 # Node ID fab0f521eeb9210c7403cc7526d5ac1394e110f6 # Parent c2f5fbca47cfdc84eeb6230e756340652ccf3ffd Coupled the method of first-attribute access with the nature of the access. diff -r c2f5fbca47cf -r fab0f521eeb9 deducer.py --- a/deducer.py Fri Sep 30 15:26:59 2016 +0200 +++ b/deducer.py Fri Sep 30 17:40:53 2016 +0200 @@ -1768,6 +1768,11 @@ provided_by_class = "" in provider_kinds provided_by_instance = "" in provider_kinds + # Determine how attributes may be accessed relative to the accessor. + + object_relative = class_accessor or module_accessor or provided_by_instance + class_relative = instance_accessor and provided_by_class + # Identify the last static attribute for context acquisition. base = None @@ -1849,7 +1854,7 @@ # Identified attribute that must be accessed via its parent. - if attr and attr.get_name() and (not attr.static() or location in self.reference_assignments): + if attr and attr.get_name() and location in self.reference_assignments: method = "direct"; origin = attr.get_name() # Static, identified attribute. @@ -1860,17 +1865,15 @@ # Attribute accessed at a known position via its parent. elif base or dynamic_base: - method = "relative"; origin = None + method = "relative" + (object_relative and "-object" or "") + \ + (class_relative and "-class" or "") + origin = None # The fallback case is always run-time testing and access. else: - l = [] - if class_accessor or module_accessor or provided_by_instance: - l.append("checkobject") - if instance_accessor and provided_by_class: - l.append("checkclass") - method = "+".join(l) + method = "check" + (object_relative and "-object" or "") + \ + (class_relative and "-class" or "") origin = None return base or name, traversed, attrnames, method, test, origin diff -r c2f5fbca47cf -r fab0f521eeb9 tests/chain.py --- a/tests/chain.py Fri Sep 30 15:26:59 2016 +0200 +++ b/tests/chain.py Fri Sep 30 17:40:53 2016 +0200 @@ -8,9 +8,17 @@ return self.o.__len__ n = 123 o = "123" + p = "456" q = 789 + class F(E): + def r(self, y): + s = self.o + C.D.F.t = 234 + return self.o.__len__ + t = 123 + def main(): c = C d = C.D