-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
29 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,7 @@ | ||
from __future__ import annotations | ||
|
||
import typing | ||
from typing import overload | ||
|
||
from htmltools import TagAttrs, TagAttrValue, TagChild, div | ||
|
||
from ..._typing_extensions import TypeGuard | ||
|
||
TagChildT = typing.TypeVar("TagChildT", bound=TagChild) | ||
|
||
|
||
# If no children are provided, it will not be able to infer the type of `TagChildT`. | ||
# Using `TagChild` | ||
@overload | ||
def consolidate_attrs( | ||
*args: TagAttrs, | ||
**kwargs: TagAttrValue, | ||
) -> tuple[TagAttrs, list[TagChild]]: | ||
... | ||
|
||
|
||
# Same as original definition | ||
@overload | ||
def consolidate_attrs( | ||
*args: TagChildT | TagAttrs, | ||
**kwargs: TagAttrValue, | ||
) -> tuple[TagAttrs, list[TagChildT]]: | ||
... | ||
|
||
|
||
def consolidate_attrs( | ||
*args: TagChildT | TagAttrs, | ||
**kwargs: TagAttrValue, | ||
) -> tuple[TagAttrs, list[TagChildT]]: | ||
tag = div(*args, **kwargs) | ||
|
||
# `TagAttrs` currently isn't compatible with `htmltools._core.TagAttrDict` | ||
# https://github.com/posit-dev/py-htmltools/pull/55 | ||
# Convert to a plain dict to avoid getting custom methods from TagAttrDict | ||
# Cast to `TagAttrs` so that `Tag` functions will accept the dictionary. | ||
attrs = typing.cast(TagAttrs, dict(tag.attrs)) | ||
|
||
# Do not alter children structure (like `TagList` does) | ||
children = [child for child in args if not isinstance(child, dict)] | ||
return (attrs, children) | ||
|
||
|
||
def is_01_scalar(x: object) -> TypeGuard[float]: | ||
return isinstance(x, (int, float)) and x >= 0.0 and x <= 1.0 | ||
|
||
|
||
@overload | ||
def trinary(x: None) -> None: | ||
... | ||
|
||
|
||
@overload | ||
def trinary(x: bool | str) -> str: | ||
... | ||
|
||
|
||
def trinary(x: bool | str | None) -> None | str: | ||
if x is None: | ||
return None | ||
elif x: | ||
return "true" | ||
else: | ||
return "false" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters