# HG changeset patch # User Paul Boddie # Date 1351443690 -3600 # Node ID af8a6a38eeede11a33768be0c1b97b6814f4a99e # Parent 1f315a42de7983a7ceb11a1b557bfc15c2d2d414 Introduced an underlying Namespace class in order to support a convenience method providing static attribute details. diff -r 1f315a42de79 -r af8a6a38eeed micropython/basicdata.py --- a/micropython/basicdata.py Mon Oct 22 00:11:06 2012 +0200 +++ b/micropython/basicdata.py Sun Oct 28 18:01:30 2012 +0100 @@ -39,10 +39,29 @@ else: return self.parent.full_name() +class Namespace: + + "A mix-in providing basic namespace functionality." + + def get_static_attribute(self, name): + + """ + Return a static attribute for the given 'name' or None if no such + attribute exists. + """ + + return None + +class Constant: + + "A superclass for all constant or context-free structures." + + pass + # Instances are special in that they need to be wrapped together with context in # a running program, but they are not generally constant. -class Instance: +class Instance(Namespace): "A placeholder indicating the involvement of an instance." @@ -74,12 +93,6 @@ def make_instance(): return common_instance -class Constant: - - "A superclass for all constant or context-free structures." - - pass - # Data objects appearing in programs before run-time. class Const(Constant, Instance): diff -r 1f315a42de79 -r af8a6a38eeed micropython/data.py --- a/micropython/data.py Mon Oct 22 00:11:06 2012 +0200 +++ b/micropython/data.py Sun Oct 28 18:01:30 2012 +0100 @@ -65,7 +65,7 @@ except NameError: from sets import Set as set -class NamespaceDict: +class NamespaceDict(Namespace): "A mix-in providing dictionary methods." @@ -1656,6 +1656,15 @@ self.allattr[name] = attr return self.allattr + def get_static_attribute(self, name): + + """ + Return a static attribute for the given 'name' or None if no such + attribute exists. + """ + + return self.all_class_attributes().get(name) + class TypeClass(Class): "A special class for the type class." @@ -2080,6 +2089,15 @@ return dict(self) + def get_static_attribute(self, name): + + """ + Return a static attribute for the given 'name' or None if no such + attribute exists. + """ + + return self.get(name) + def modify_name(self, name): """