I have a non-trivial list comprehension in Python. My goal is to take a whitespace-delimited list of strings from an XML attribute — which may not exist — and look up the corresponding constant in my module — which may not exist — and create a set of the results.
What's the accepted way to format such a beast? They all make me want to vomit a little.
self.types = frozenset(
v for v in (
getattr(objects_module,enum_name,None)
for enum_name in element.attrib.get('object-types', '').split())
if v)
self.types = frozenset(
v
for v in (getattr(objects_module,enum_name,None)
for enum_name in element.attrib.get('object-types', '').split())
if v)
self.types = frozenset(
v for v in (
getattr(objects_module,enum_name,None)
for enum_name in element.attrib.get('object-types', '').split()
) if v
)
self.types = frozenset(v for v in (getattr(objects_module,enum_name,None) for enum_name in element.attrib.get('object-types', '').split()) if v)