Comment 0 for bug 512114

Revision history for this message
Siegfried Gevatter (rainct) wrote :

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:

--------------------------------------------
FAIL: testConstruct (__main__.SymbolCollectionTest)

Traceback (most recent call last):
  File "./test/datamodel-test.py", line 46, in testConstruct
    self.assertRaises(AttributeError, getattr, foo, "test2")
AssertionError: AttributeError not raised
--------------------------------------------

So, what was that supposed to do? And what behavior should SymbolCollection.__getattr__ have?