Make getdotattr always return a flat list
This commit is contained in:
@@ -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:
|
||||
|
@@ -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):
|
||||
|
Reference in New Issue
Block a user