From 4237e448818f50ca1a7641b857c48efd11915c5d Mon Sep 17 00:00:00 2001 From: Andreas Pelme Date: Sun, 23 Jun 2024 20:09:03 +0200 Subject: [PATCH] html2htpy: simplify attrs serialization --- htpy/html2htpy.py | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/htpy/html2htpy.py b/htpy/html2htpy.py index 9517b33..36f3aa6 100644 --- a/htpy/html2htpy.py +++ b/htpy/html2htpy.py @@ -48,21 +48,11 @@ def serialize(self, shorthand_id_class: bool, use_h_prefix: bool) -> str: _attrs = "" _kwattrs: list[tuple[str, str | None]] = [] - for a in self.attrs: - key = a[0] - if key == "class": - if shorthand_id_class: - _positional_attrs[key] = a[1] - else: - _kwattrs.append(a) - - elif key == "id": - if shorthand_id_class: - _positional_attrs[key] = a[1] - else: - _kwattrs.append(a) + for key, value in self.attrs: + if key in ("id", "class") and shorthand_id_class: + _positional_attrs[key] = value else: - _kwattrs.append(a) + _kwattrs.append((key, value)) if _positional_attrs or _kwattrs: _attrs += "("