Skip to content

Commit

Permalink
Fix mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
MaddyGuthridge committed Feb 10, 2024
1 parent 7b38964 commit 6e55c93
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
7 changes: 1 addition & 6 deletions pyhtml/__tag_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"</{self._get_tag_name()}>")

Expand Down
20 changes: 18 additions & 2 deletions pyhtml/__tags/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def __init__(
super().__init__(**attributes)

# Form submission
@overload
@overload # type: ignore
def __call__(
self,
*,
Expand Down Expand Up @@ -460,7 +460,7 @@ def __call__(
) -> None:
...

# default, allowing all arguments
# default, suggesting types
@overload
def __call__(
self,
Expand All @@ -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,
*,
Expand Down
13 changes: 0 additions & 13 deletions pyhtml/__util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6e55c93

Please sign in to comment.