Need clarification on SymbolCollection.__getattr__
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Zeitgeist Framework |
Fix Released
|
Medium
|
Unassigned |
Bug Description
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(
self.
return getattr(self, name)
-------
The penultimate line 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/
-------
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:
-------
FAIL: testConstruct (__main_
Traceback (most recent call last):
File "./test/
self.
AssertionError: AttributeError not raised
-------
So, what was that supposed to do? And what behavior should SymbolCollectio
Related branches
Changed in zeitgeist: | |
importance: | Undecided → Medium |
milestone: | none → 0.3.3 |
description: | updated |
Changed in zeitgeist: | |
status: | New → Fix Released |
Well, in the passt SymbolCollectio n.__dict_ _ was the place where all Symbols where managed, all symbols where in fact real attributes of SymbolCollection. n.__getattr_ _() is only invoked if the attribute-name is not found in __dict__, so what this method did was: if there is not attrbute with given name and the given name is uppercase, we assue that this is a new (temporary) Symbol, so a new one is created. So there is nothing unconditionally there.
SymbolCollectio
I don't understand why SymbolCollection was changed at all, as far as I can see there is not good reason for it, the "old" implementation was faster, and less memory consuming.
I also don't get why we need a lookup by URI, but if we need this we should not abuse __getitem__() for this but add a method like find_by_uri()