micropython

Changeset

551:c46e8aca4726
2012-06-22 Paul Boddie raw files shortlog changelog graph 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.
micropython/data.py (file) tests/class_method_alias.py (file) tests/class_method_usage.py (file)
     1.1 --- a/micropython/data.py	Wed Jun 20 00:44:03 2012 +0200
     1.2 +++ b/micropython/data.py	Fri Jun 22 00:11:51 2012 +0200
     1.3 @@ -183,7 +183,7 @@
     1.4              node._scope = scope
     1.5              self.note_scope(name, scope)
     1.6  
     1.7 -        if full_name is not None and (scope != "local" or self is self.module):
     1.8 +        if full_name is not None and (scope != "local" or isinstance(self, (Class, Module))):
     1.9              self.use_specific_attribute(full_name, name)
    1.10  
    1.11          return attr
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tests/class_method_alias.py	Fri Jun 22 00:11:51 2012 +0200
     2.3 @@ -0,0 +1,15 @@
     2.4 +#!/usr/bin/env python
     2.5 +
     2.6 +class C:
     2.7 +    def f(self):
     2.8 +        return 1
     2.9 +    m = f
    2.10 +
    2.11 +    def g(self):
    2.12 +        return 2
    2.13 +    n = g
    2.14 +
    2.15 +c = C()
    2.16 +result_1 = c.m()
    2.17 +
    2.18 +# vim: tabstop=4 expandtab shiftwidth=4
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tests/class_method_usage.py	Fri Jun 22 00:11:51 2012 +0200
     3.3 @@ -0,0 +1,18 @@
     3.4 +#!/usr/bin/env python
     3.5 +
     3.6 +def p(x):
     3.7 +    return x
     3.8 +
     3.9 +class C:
    3.10 +    def f(self):
    3.11 +        return 1
    3.12 +    m = p(f)
    3.13 +
    3.14 +    def g(self):
    3.15 +        return 2
    3.16 +    n = p(g)
    3.17 +
    3.18 +c = C()
    3.19 +result_1 = c.m()
    3.20 +
    3.21 +# vim: tabstop=4 expandtab shiftwidth=4