From 6e55c93cf4d41f1a8e630bde49821dfd39df96d2 Mon Sep 17 00:00:00 2001 From: Miguel Guthridge Date: Sat, 10 Feb 2024 18:14:11 +1100 Subject: [PATCH] Fix mypy --- pyhtml/__tag_base.py | 7 +------ pyhtml/__tags/input.py | 20 ++++++++++++++++++-- pyhtml/__util.py | 13 ------------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/pyhtml/__tag_base.py b/pyhtml/__tag_base.py index 23822f1..f1e0b9b 100644 --- a/pyhtml/__tag_base.py +++ b/pyhtml/__tag_base.py @@ -97,12 +97,7 @@ def _render(self) -> list[str]: else: out = [opening] # Children - out.extend( - util.render_children( - # Instantiate types as empty tags - util.instantiate_tag_types(self.children) - ) - ) + out.extend(util.render_children(self.children)) # Closing tag out.append(f"") diff --git a/pyhtml/__tags/input.py b/pyhtml/__tags/input.py index c4b3a22..f7c0964 100644 --- a/pyhtml/__tags/input.py +++ b/pyhtml/__tags/input.py @@ -304,7 +304,7 @@ def __init__( super().__init__(**attributes) # Form submission - @overload + @overload # type: ignore def __call__( self, *, @@ -460,7 +460,7 @@ def __call__( ) -> None: ... - # default, allowing all arguments + # default, suggesting types @overload def __call__( self, @@ -476,6 +476,22 @@ def __call__( ) -> None: ... + # default, allowing all arguments + @overload + def __call__( + self, + *, + type: Optional[str] = None, + id: Optional[str] = None, + name: Optional[str] = None, + value: Optional[str] = None, + placeholder: Optional[str] = None, + readonly: Optional[bool] = None, + required: Optional[bool] = None, + **attributes: AttributeType, + ) -> None: + ... + def __call__( # type: ignore self, *, diff --git a/pyhtml/__util.py b/pyhtml/__util.py index 7426309..c3a008d 100644 --- a/pyhtml/__util.py +++ b/pyhtml/__util.py @@ -139,19 +139,6 @@ def flatten_list(the_list: list[ChildrenType]) -> list[ChildElementType]: return result -def instantiate_tag_types(elements: list[Any]) -> list[Any]: - """ - Map a list so that any element e for which issubclass(e, Tag) returns True - is instantiated - """ - # Can't wait for lazy imports in Python 3.12 - from .__tag_base import Tag - return list(map( - lambda e: e() if isinstance(e, type) and issubclass(e, Tag) else e, - elements, - )) - - def dict_union(base: dict[K, V], additions: dict[K, V]) -> dict[K, V]: """ Smart union of a dictionary - if a value in `base` is `None` and the