1.1 --- a/micropython/data.py Sun Jun 19 02:01:51 2011 +0200
1.2 +++ b/micropython/data.py Sun Jun 19 02:07:58 2011 +0200
1.3 @@ -174,7 +174,7 @@
1.4 node._scope = scope
1.5 self.note_scope(name, scope)
1.6
1.7 - if full_name is not None:
1.8 + if full_name is not None and (scope != "local" or self is self.module):
1.9 self.use_specific_attribute(full_name, name)
1.10
1.11 return attr
1.12 @@ -470,7 +470,7 @@
1.13 # These shadow various methods in the InspectedModule class, and provide
1.14 # implementations generally.
1.15
1.16 - def _use_specific_attribute(self, objname, attrname):
1.17 + def _use_specific_attribute(self, objname, attrname, from_name=None):
1.18
1.19 """
1.20 Note attribute usage specifically on 'objname' - an object which is
1.21 @@ -480,7 +480,7 @@
1.22 This bypasses attribute user mechanisms.
1.23 """
1.24
1.25 - from_name = self.full_name()
1.26 + from_name = from_name or self.full_name()
1.27 objname = objname or from_name
1.28 module = self.module
1.29 importer = module and module.importer
2.1 --- a/micropython/inspect.py Sun Jun 19 02:01:51 2011 +0200
2.2 +++ b/micropython/inspect.py Sun Jun 19 02:07:58 2011 +0200
2.3 @@ -398,7 +398,7 @@
2.4
2.5 return self.get_namespace()._use_attribute(name, attrname, value)
2.6
2.7 - def use_specific_attribute(self, objname, attrname):
2.8 + def use_specific_attribute(self, objname, attrname, from_name=None):
2.9
2.10 """
2.11 Note usage on the object having the given 'objname' of the attribute
2.12 @@ -406,7 +406,7 @@
2.13 object providing the attribute.
2.14 """
2.15
2.16 - return self.get_namespace()._use_specific_attribute(objname, attrname)
2.17 + return self.get_namespace()._use_specific_attribute(objname, attrname, from_name)
2.18
2.19 # Visitor methods.
2.20
2.21 @@ -657,7 +657,14 @@
2.22 # NOTE: Consider not registering assignments involving methods, since
2.23 # NOTE: this is merely creating aliases for such methods.
2.24
2.25 - self.use_specific_attribute(None, node.name)
2.26 + if isinstance(self.get_namespace(), (Class, Module)):
2.27 + if not isinstance(self.expr, Attr) or not isinstance(self.expr.get_value(), Function):
2.28 + self.use_specific_attribute(None, node.name)
2.29 + else:
2.30 + fn = self.expr.get_value()
2.31 + ns = self.get_namespace().full_name()
2.32 + self.use_specific_attribute(fn.parent.full_name(), fn.name, "%s.%s" % (ns, node.name))
2.33 +
2.34 return None
2.35
2.36 visitAssTuple = visitAssList
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/tests/class_function_assignment.py Sun Jun 19 02:07:58 2011 +0200
3.3 @@ -0,0 +1,16 @@
3.4 +#!/usr/bin/env python
3.5 +
3.6 +def f(self, x):
3.7 + return 2
3.8 +
3.9 +class C:
3.10 + def g(self, x):
3.11 + return 1
3.12 + h = f
3.13 +
3.14 +c = C()
3.15 +result_1 = c.g(123)
3.16 +#result_2 = c.h(123)
3.17 +result_2 = f(123, 456)
3.18 +
3.19 +# vim: tabstop=4 expandtab shiftwidth=4
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/tests/class_function_assignment_unused.py Sun Jun 19 02:07:58 2011 +0200
4.3 @@ -0,0 +1,16 @@
4.4 +#!/usr/bin/env python
4.5 +
4.6 +def f(self, x):
4.7 + return 2
4.8 +
4.9 +class C:
4.10 + def g(self, x):
4.11 + return 1
4.12 + h = f
4.13 +
4.14 +c = C()
4.15 +result_1 = c.g(123)
4.16 +#result_2 = c.h(123)
4.17 +#result_2 = f(123, 456)
4.18 +
4.19 +# vim: tabstop=4 expandtab shiftwidth=4
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/tests/class_function_assignment_using_target.py Sun Jun 19 02:07:58 2011 +0200
5.3 @@ -0,0 +1,16 @@
5.4 +#!/usr/bin/env python
5.5 +
5.6 +def f(self, x):
5.7 + return 2
5.8 +
5.9 +class C:
5.10 + def g(self, x):
5.11 + return 1
5.12 + h = f
5.13 +
5.14 +c = C()
5.15 +result_1 = c.g(123)
5.16 +result_2 = c.h(123)
5.17 +#result_2 = f(123, 456)
5.18 +
5.19 +# vim: tabstop=4 expandtab shiftwidth=4