Skip to content

Commit

Permalink
Change type annotation of _add_ws (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
wch authored Nov 2, 2023
1 parent eafad82 commit e245678
Show file tree
Hide file tree
Showing 6 changed files with 377 additions and 363 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [UNRELEASED]

* Changed the type annotation of `_add_ws` from `bool` to `TagAttrValue`. This makes it easier to write functions which call `Tag` functions and pass along `**kwargs`. (#67)


## [0.4.1] 2023-10-30

* Fixed deserialization of JSON HTML dependencies when they contained newline characters. (#65)
Expand Down
2 changes: 1 addition & 1 deletion htmltools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.4.1"
__version__ = "0.4.1.9000"

from . import svg, tags
from ._core import TagAttrArg # pyright: ignore[reportUnusedImport] # noqa: F401
Expand Down
13 changes: 11 additions & 2 deletions htmltools/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@ class Tag:
*args
Children for the tag.
_add_ws
Whether to add whitespace surrounding the tag (see Note for details).
A ``bool`` indicating whether to add whitespace surrounding the tag (see Note
for details).
**kwargs
Attributes for the tag.
Expand Down Expand Up @@ -522,10 +523,18 @@ def __init__(
self,
_name: str,
*args: TagChild | TagAttrs,
_add_ws: bool = True,
_add_ws: TagAttrValue = True,
**kwargs: TagAttrValue,
) -> None:
self.name = _name

# Note that _add_ws is marked as a TagAttrValue for the sake of static type
# checking, but it must in fact be a bool. This is due to limitations in
# Python's type system when passing along **kwargs.
# https://github.com/posit-dev/py-htmltools/pull/67
if not isinstance(_add_ws, bool):
raise TypeError("`_add_ws` must be `True` or `False`")

self.add_ws = _add_ws

attrs = [x for x in args if isinstance(x, dict)]
Expand Down
Loading

0 comments on commit e245678

Please sign in to comment.