spec.py: early return in __str__

This commit is contained in:
Harmen Stoppels 2024-04-18 13:52:05 +02:00 committed by Harmen Stoppels
parent b362362291
commit 2bc2902fed

View file

@ -911,6 +911,9 @@ def flags():
yield flags yield flags
def __str__(self): def __str__(self):
if not self:
return ""
sorted_items = sorted((k, v) for k, v in self.items() if v) sorted_items = sorted((k, v) for k, v in self.items() if v)
result = "" result = ""
@ -4563,6 +4566,8 @@ def format_path(
return str(path_ctor(*output_path_components)) return str(path_ctor(*output_path_components))
def __str__(self): def __str__(self):
if not self._dependencies:
return self.format()
root_str = [self.format()] root_str = [self.format()]
sorted_dependencies = sorted( sorted_dependencies = sorted(
self.traverse(root=False), key=lambda x: (x.name, x.abstract_hash) self.traverse(root=False), key=lambda x: (x.name, x.abstract_hash)