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('.'):
|
for path in dot_path.split('.'):
|
||||||
getter = attrgetter(path)
|
getter = attrgetter(path)
|
||||||
if isinstance(last, list):
|
if isinstance(last, list):
|
||||||
tmp = []
|
last = sum((getter(el) for el in last), [])
|
||||||
for el in last:
|
|
||||||
if isinstance(el, list):
|
|
||||||
tmp.extend(map(getter, el))
|
|
||||||
else:
|
|
||||||
tmp.append(getter(el))
|
|
||||||
last = tmp
|
|
||||||
elif isinstance(last, InstrumentedAttribute):
|
elif isinstance(last, InstrumentedAttribute):
|
||||||
last = getter(last.property.mapper.class_)
|
last = getter(last.property.mapper.class_)
|
||||||
elif last is None:
|
elif last is None:
|
||||||
|
@@ -67,11 +67,12 @@ class TestGetDotAttr(TestCase):
|
|||||||
subsection = self.SubSection(section=section)
|
subsection = self.SubSection(section=section)
|
||||||
subsubsection = self.SubSubSection(subsection=subsection)
|
subsubsection = self.SubSubSection(subsection=subsection)
|
||||||
|
|
||||||
|
assert getdotattr(document, 'sections') == [section]
|
||||||
assert getdotattr(document, 'sections.subsections') == [
|
assert getdotattr(document, 'sections.subsections') == [
|
||||||
[subsection]
|
subsection
|
||||||
]
|
]
|
||||||
assert getdotattr(document, 'sections.subsections.subsubsections') == [
|
assert getdotattr(document, 'sections.subsections.subsubsections') == [
|
||||||
[subsubsection]
|
subsubsection
|
||||||
]
|
]
|
||||||
|
|
||||||
def test_class_paths(self):
|
def test_class_paths(self):
|
||||||
|
Reference in New Issue
Block a user