# HG changeset patch # User Paul Boddie # Date 1340316711 -7200 # Node ID c46e8aca4726b4202a8233116c9c2a14cc762b5a # Parent 1b42eee2b7499784889dc0158439d4b570bba342 Made sure that local name usage is tracked for classes as well as modules. Without such tracking, usage of class attributes at class definition time is not recorded, and anything beyond simple aliasing of attributes causes usage of those attributes to go undetected and for those attributes to be vacuumed. diff -r 1b42eee2b749 -r c46e8aca4726 micropython/data.py --- a/micropython/data.py Wed Jun 20 00:44:03 2012 +0200 +++ b/micropython/data.py Fri Jun 22 00:11:51 2012 +0200 @@ -183,7 +183,7 @@ node._scope = scope self.note_scope(name, scope) - if full_name is not None and (scope != "local" or self is self.module): + if full_name is not None and (scope != "local" or isinstance(self, (Class, Module))): self.use_specific_attribute(full_name, name) return attr diff -r 1b42eee2b749 -r c46e8aca4726 tests/class_method_alias.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/class_method_alias.py Fri Jun 22 00:11:51 2012 +0200 @@ -0,0 +1,15 @@ +#!/usr/bin/env python + +class C: + def f(self): + return 1 + m = f + + def g(self): + return 2 + n = g + +c = C() +result_1 = c.m() + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 1b42eee2b749 -r c46e8aca4726 tests/class_method_usage.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/class_method_usage.py Fri Jun 22 00:11:51 2012 +0200 @@ -0,0 +1,18 @@ +#!/usr/bin/env python + +def p(x): + return x + +class C: + def f(self): + return 1 + m = p(f) + + def g(self): + return 2 + n = p(g) + +c = C() +result_1 = c.m() + +# vim: tabstop=4 expandtab shiftwidth=4