home · contact · privacy
Merge _WithDb into _Lookupables, for now all of the latter need it.
authorPlom Heller <plom@plomlompom.com>
Sun, 4 Oct 2026 17:41:54 +0000 (19:41 +0200)
committerPlom Heller <plom@plomlompom.com>
Sun, 4 Oct 2026 17:41:54 +0000 (19:41 +0200)
src/bricksplom/misc.py

index f0bf6de104319b79b8adacbf3bdc61e21e8b3247..61a1d9d1ca2280560515faa80849bbbcbd1244ea 100644 (file)
@@ -91,7 +91,7 @@ class _Textfiled(ABC):
     def from_textfile(
             cls,
             path: tuple[str, str],
-            **kwargs
+            db: 'BricksDb'
             ) -> dict[str, Self]:
         'Build from file at path.'
 
@@ -105,8 +105,10 @@ class _Textfiled(ABC):
         return self.raw()
 
 
-class _WithDb:
-    'Add db:Optional[BricksDB] field to __init__, setting .db.'
+class _Lookupable:
+    'Adds .db, provides methods for BricksDb.lookup and .id_ padding.'
+    _id_indent: int = 0
+    id_: str
 
     def __init__(
             self,
@@ -116,12 +118,6 @@ class _WithDb:
         self.db = db
         super().__init__(**kwargs)
 
-
-class _Lookupable:
-    'Provides methods for BricksDb.lookup and .id_ padding.'
-    _id_indent: int = 0
-    id_: str
-
     @classmethod
     def indent_id(
             cls,
@@ -228,7 +224,7 @@ class _Lookupable:
             }
 
 
-class _BrickColor(_Textfiled, _Lookupable, _WithDb):
+class _BrickColor(_Textfiled, _Lookupable):
     'Color incl. solidness/transparency field.'
     _id_indent = 3
 
@@ -248,8 +244,7 @@ class _BrickColor(_Textfiled, _Lookupable, _WithDb):
     def from_textfile(
             cls,
             path: tuple[str, str],
-            db: Optional['BricksDb'] = None,
-            **_
+            db: 'BricksDb'
             ) -> dict[str, Self]:
         collected = {}
         for id_, desc in [cls.tokify(line, 2) for line in cls.lines_of(path)]:
@@ -375,7 +370,7 @@ class _BrickDesignData:
         return attrs
 
 
-class _BrickDesign(_Textfiled, _WithDb, _Lookupable):
+class _BrickDesign(_Textfiled, _Lookupable):
     'Shape and texture configurations with descriptions and equalities.'
     _id_indent = 6
     alternate_to: Optional[Self] = None
@@ -508,8 +503,7 @@ class _BrickDesign(_Textfiled, _WithDb, _Lookupable):
     def from_textfile(
             cls,
             path: tuple[str, str],
-            db: Optional['BricksDb'] = None,
-            **_
+            db: 'BricksDb',
             ) -> dict[str, Self]:
         collected = {}
         alts: dict[str, set[str]] = {}
@@ -546,7 +540,7 @@ class _BrickDesign(_Textfiled, _WithDb, _Lookupable):
         return f'{raw}{_CHAR_SEP_TOKEN.join(attrs)}'
 
 
-class _Brick(_Textfiled, _WithDb, _Lookupable):
+class _Brick(_Textfiled, _Lookupable):
     'Individual configuration of design and color.'
     _id_indent = 7
 
@@ -575,8 +569,7 @@ class _Brick(_Textfiled, _WithDb, _Lookupable):
     def from_textfile(
             cls,
             path: tuple[str, str],
-            db: Optional['BricksDb'] = None,
-            **_
+            db: 'BricksDb'
             ) -> dict[str, Self]:
         collected = {}
         for toks in [cls.tokify(line, 3) for line in cls.lines_of(path)]:
@@ -607,7 +600,7 @@ class _Brick(_Textfiled, _WithDb, _Lookupable):
                 f'{design.description} ({color}){comment}')
 
 
-class _BrickSet(_Textfiled, _WithDb, _Lookupable):
+class _BrickSet(_Textfiled, _Lookupable):
     'Named collection of bricks in order of pages of columns of counts.'
 
     def __init__(
@@ -628,8 +621,7 @@ class _BrickSet(_Textfiled, _WithDb, _Lookupable):
     def from_textfile(
             cls,
             path: tuple[str, str],
-            db: Optional['BricksDb'] = None,
-            **_
+            db: 'BricksDb'
             ) -> dict[str, Self]:
         collected: dict[str, tuple[Optional[bool],
                                    str,
@@ -767,7 +759,7 @@ class _BrickSet(_Textfiled, _WithDb, _Lookupable):
                 }
 
 
-class _Box(_WithDb, _Lookupable):
+class _Box(_Lookupable):
     'Order of designs.'
     _id_indent = 5
 
@@ -843,9 +835,8 @@ class BricksDb:
         self._name_set_colors = name_set_colors
         for name, cls in [(name, cls) for name, cls in self.lookupables.items()
                           if issubclass(cls, _Textfiled)]:
-            kwargs = {'db': self} if issubclass(cls, _WithDb) else {}
             setattr(self, name, cls.from_textfile((path_tables, f'{name}.txt'),
-                                                  **kwargs))
+                                                  db=self))
         self.ldraw = LdrawDb(Path(path_ldraw))
         self._ldraw_modes = ldraw_modes.split(CHAR_SEP_LDRAW_MODES)
         if _LDRAW_MODE_FILL_PATHS in self._ldraw_modes: