From: Plom Heller Date: Mon, 27 Jul 2026 21:22:37 +0000 (+0200) Subject: Simplify integration of BricksDB.boxes with other tables. X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/static/todos?a=commitdiff_plain;ds=sidebyside;p=bricksplom Simplify integration of BricksDB.boxes with other tables. --- diff --git a/bricksplom.py b/bricksplom.py index 36be587..669c3f7 100755 --- a/bricksplom.py +++ b/bricksplom.py @@ -174,7 +174,7 @@ class Lookupable: ) -> tuple[Self, ...]: remains = list(pre_sorted) items: list[Self] = [] - for box in sorted(db.boxes().values(), + for box in sorted(db.boxes.values(), key=lambda box: box.id_indented()): for item_id in [t[1] for t in box.brick_listings_flat()]: if to_id_of: @@ -558,7 +558,7 @@ class BrickSet(Textfiled, WithDb, Lookupable): color = str(self._db.colors[self._db.bricks[brick_id].color_id] ).lstrip().split(CHAR_SEP_TOKEN, maxsplit=1)[1] box: Optional[Box] = None - for i_box in self._db.boxes().values(): + for i_box in self._db.boxes.values(): for idx_in_box in [ idx for idx, d_to_ls in enumerate(i_box.designs_to_listings) @@ -568,7 +568,7 @@ class BrickSet(Textfiled, WithDb, Lookupable): if box: break if not box: - for i_box in self._db.boxes().values(): + for i_box in self._db.boxes.values(): for idx_in_box in [ idx for idx, t in enumerate(i_box.designs_to_listings) @@ -648,8 +648,7 @@ class Box(WithDb, Lookupable): class BricksDb: 'Collection of all the tables enabling their combined processing.' - lookupable = frozenset( - {'boxes', 'designs', 'sets', 'colors', 'bricks'}) + lookupable = frozenset({'boxes', 'bricks', 'colors', 'designs', 'sets'}) def __init__( self, @@ -672,6 +671,7 @@ class BricksDb: design.direct_attrs.ldraw = filename self._check_consistencies(verify_ldraw='verify' in self._ldraw_mode) + @property def boxes( self ) -> dict[str, Box]: @@ -789,9 +789,8 @@ class BricksDb: sort_by: str ) -> str: 'Return result of inquiry on table of table_name.' - assert table_name in self.lookupable - maybe_dict = getattr(self, table_name) - table = maybe_dict if isinstance(maybe_dict, dict) else maybe_dict() + assert hasattr(self, table_name) and table_name in self.lookupable + table = getattr(self, table_name) if item_id: match_by = PARAM_Q_ID + item_id items = tuple(table.values())