Make getdotattr always return a flat list

This commit is contained in:
Konsta Vesterinen
2014-12-10 09:44:39 +02:00
parent fe456ff005
commit 54a713959f
2 changed files with 4 additions and 9 deletions

View File

@@ -644,13 +644,7 @@ def getdotattr(obj_or_class, dot_path):
for path in dot_path.split('.'):
getter = attrgetter(path)
if isinstance(last, list):
tmp = []
for el in last:
if isinstance(el, list):
tmp.extend(map(getter, el))
else:
tmp.append(getter(el))
last = tmp
last = sum((getter(el) for el in last), [])
elif isinstance(last, InstrumentedAttribute):
last = getter(last.property.mapper.class_)
elif last is None:

View File

@@ -67,11 +67,12 @@ class TestGetDotAttr(TestCase):
subsection = self.SubSection(section=section)
subsubsection = self.SubSubSection(subsection=subsection)
assert getdotattr(document, 'sections') == [section]
assert getdotattr(document, 'sections.subsections') == [
[subsection]
subsection
]
assert getdotattr(document, 'sections.subsections.subsubsections') == [
[subsubsection]
subsubsection
]
def test_class_paths(self):