The datamodel.py file used to have this method for SymbolCollection:
--------------------------------------------
def __getattr__(self, name):
if not name.isupper():
# symbols must be uppercase
raise AttributeError("'%s' has no attribute '%s'" %(self.__name__, name))
self.__dict__[name] = Symbol(self.__name__, name)
return getattr(self, name)
---------------------------------------------
The penultimate chapter seems to unconditionally creates a new Symbol instance, which I don't really understand but interpreted as a way to avoid an exception if the given Interpretation/Manifestation doesn't exist. I re-implemented it the following way:
--------------------------------------------
def __getattr__(self, name):
if not name in self.__symbols:
print "Unrecognized %s: %s" % (self.__name__, name)
self.__symbols[name] = Symbol(self.__name__, name)
return self.__symbols[name]
--------------------------------------------
However, it seems like my assumption was incorrect as this results in a failing unit test:
The datamodel.py file used to have this method for SymbolCollection:
------- ------- ------- ------- ------- ------- -- "'%s' has no attribute '%s'" %(self.__name__, name)) __dict_ _[name] = Symbol( self.__ name__, name) ------- ------- ------- ------- ------- ---
def __getattr__(self, name):
if not name.isupper():
# symbols must be uppercase
raise AttributeError(
self.
return getattr(self, name)
-------
The penultimate chapter seems to unconditionally creates a new Symbol instance, which I don't really understand but interpreted as a way to avoid an exception if the given Interpretation/ Manifestation doesn't exist. I re-implemented it the following way:
------- ------- ------- ------- ------- ------- -- __symbols[ name] = Symbol( self.__ name__, name) symbols[ name] ------- ------- ------- ------- ------- --
def __getattr__(self, name):
if not name in self.__symbols:
print "Unrecognized %s: %s" % (self.__name__, name)
self.
return self.__
-------
However, it seems like my assumption was incorrect as this results in a failing unit test:
------- ------- ------- ------- ------- ------- -- _.SymbolCollect ionTest)
FAIL: testConstruct (__main_
Traceback (most recent call last): datamodel- test.py" , line 46, in testConstruct assertRaises( AttributeError, getattr, foo, "test2") ------- ------- ------- ------- ------- --
File "./test/
self.
AssertionError: AttributeError not raised
-------
So, what was that supposed to do? And what behavior should SymbolCollectio n.__getattr_ _ have?