From c1c15bc28ef631b5093682a6624cb26e4c160cc5 Mon Sep 17 00:00:00 2001 From: Tom Close Date: Tue, 17 Sep 2024 18:29:12 +1000 Subject: [PATCH] truncate set repr after 3 paths --- fileformats/generic/set.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fileformats/generic/set.py b/fileformats/generic/set.py index 7484086..c6c3194 100644 --- a/fileformats/generic/set.py +++ b/fileformats/generic/set.py @@ -13,6 +13,18 @@ class TypedSet(FileSet): content_types: ty.Tuple[ty.Type[FileSet], ...] = () + MAX_REPR_PATHS = 3 + + def __repr__(self) -> str: + paths_repr = ( + "'" + + "', '".join(str(p) for p in sorted(self.fspaths)[: self.MAX_REPR_PATHS]) + + "'" + ) + if len(self.fspaths) > self.MAX_REPR_PATHS: + paths_repr += ", ..." + return f"{self.type_name}({paths_repr})" + @cached_property def contents(self) -> ty.List[FileSet]: contnts = []