# HG changeset patch # User Paul Boddie # Date 1339259282 -7200 # Node ID 46d9438f5a384204c943fdbd318f12e7551ded62 # Parent 0f9aa4c4d92c16851f5ce7836f77416e9f99b9d8 Introduced attribute usage branching for logical operators along with a test. diff -r 0f9aa4c4d92c -r 46d9438f5a38 micropython/inspect.py --- a/micropython/inspect.py Sat Jun 09 18:27:00 2012 +0200 +++ b/micropython/inspect.py Sat Jun 09 18:28:02 2012 +0200 @@ -462,7 +462,23 @@ def TEST_OP(self, node): self.use_name("__bool__", node) - return self.OP(node) + self.new_branchpoint() + + # Propagate attribute usage to branches. + # Each node starts a new conditional region, effectively making a deeply + # nested collection of if-like statements. + + for n in node.nodes: + self.new_branch(n) + self.dispatch(n) + + # The nested regions must be terminated. + + for n in node.nodes: + self.shelve_branch() + + self.merge_branches() + return make_instance() # Generic support for classes of operations. @@ -1158,7 +1174,10 @@ def visitName(self, node): return self.get_namespace().get_using_node(node.name, node) or make_instance() - visitNot = TEST_OP + def visitNot(self, node): + self.use_name("__bool__", node) + self.dispatch(node.expr) + return make_instance() visitOr = TEST_OP diff -r 0f9aa4c4d92c -r 46d9438f5a38 tests/attribute_access_type_restriction_logical.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/attribute_access_type_restriction_logical.py Sat Jun 09 18:28:02 2012 +0200 @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +class C: + def f(self): + return 1 + def g(self): + return 2 + +class D: + def f(self): + return 0 + +def test(x): + if x.f() and x.g(): + return 3 + else: + return 4 + +def test2(x): + if not x.f() or x.g(): + return 5 + else: + return 6 + +c = C() +d = D() +result_4 = test(d) +result_5 = test2(d) + +# vim: tabstop=4 expandtab shiftwidth=4