Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion meta/generate_tag_defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def _escape_children(self) -> bool:
"""

GET_PRE_CONTENT = """
def _get_tag_pre_content(self) -> Optional[str]:
def _get_tag_pre_content(self) -> str | None:
return {}
"""

Expand Down
28 changes: 14 additions & 14 deletions meta/scrape_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import sys
from collections.abc import Iterator
from dataclasses import dataclass
from typing import Any, Optional, TypedDict, Union
from typing import Any, TypedDict

import requests
import yaml
Expand Down Expand Up @@ -42,7 +42,7 @@
"""


def htmlElementReplace(lookup: str, presentation: Optional[str] = None) -> str:
def htmlElementReplace(lookup: str, presentation: str | None = None) -> str:
"""
Replace text in an HTML reference
"""
Expand All @@ -54,7 +54,7 @@ def htmlElementReplace(lookup: str, presentation: Optional[str] = None) -> str:
return f"[{presentation}]({url})"


def glossaryReplace(lookup: str, presentation: Optional[str] = None) -> str:
def glossaryReplace(lookup: str, presentation: str | None = None) -> str:
"""
Replace text in a glossary reference
"""
Expand All @@ -66,7 +66,7 @@ def glossaryReplace(lookup: str, presentation: Optional[str] = None) -> str:
return f"[{presentation}]({url})"


def cssXrefReplace(lookup: str, presentation: Optional[str] = None) -> str:
def cssXrefReplace(lookup: str, presentation: str | None = None) -> str:
"""
Replace text for CSS cross reference lookup
"""
Expand All @@ -78,7 +78,7 @@ def cssXrefReplace(lookup: str, presentation: Optional[str] = None) -> str:
return f"[{presentation}]({url})"


def domXrefReplace(lookup: str, presentation: Optional[str] = None) -> str:
def domXrefReplace(lookup: str, presentation: str | None = None) -> str:
"""
Replace text for DOM cross reference lookup
"""
Expand Down Expand Up @@ -137,7 +137,7 @@ class TagsYmlItem(TypedDict):
skip: NotRequired[bool]
"""Whether to skip this tag when generating tags"""

attributes: NotRequired[dict[str, Union[str, AttrYmlItem]]]
attributes: NotRequired[dict[str, str | AttrYmlItem]]
"""Mapping of attributes used by the tag (name: description)"""

base: NotRequired[str]
Expand Down Expand Up @@ -175,7 +175,7 @@ class Attr:
Name of the attribute
"""

doc: Optional[str]
doc: str | None
"""
Documentation of the attribute if applicable
"""
Expand All @@ -185,7 +185,7 @@ class Attr:
Type to accept for the attribute
"""

default: Optional[Any]
default: Any | None
"""
Default value for the attribute
"""
Expand Down Expand Up @@ -227,12 +227,12 @@ class TagInfo:
List of attributes and their documentation.
"""

pre_content: Optional[str]
pre_content: str | None
"""
Pre-content for the element (eg `<!DOCTYPE html>`)
"""

render_options: Optional[RenderOptions]
render_options: RenderOptions | None
"""
Render options
"""
Expand Down Expand Up @@ -419,8 +419,8 @@ def attr_entries_to_object(tags: TagsYaml, tag_name: str) -> list[Attr]:
attrs = []
for name, value in tag_data["attributes"].items():
if isinstance(value, str):
doc: Optional[str] = value
default: Optional[str] = None
doc: str | None = value
default: str | None = None
type = "AttributeType"
else:
doc = value.get("doc")
Expand Down Expand Up @@ -479,7 +479,7 @@ def get_tag_escape_children(tags: TagsYaml, tag_name: str) -> bool:
return tag.get("escape_children", True)


def get_tag_pre_content(tags: TagsYaml, tag_name: str) -> Optional[str]:
def get_tag_pre_content(tags: TagsYaml, tag_name: str) -> str | None:
"""
Return pre-content for the tag
"""
Expand All @@ -491,7 +491,7 @@ def get_tag_pre_content(tags: TagsYaml, tag_name: str) -> Optional[str]:

def get_tag_render_options(
tags: TagsYaml, tag_name: str
) -> Optional[RenderOptions]:
) -> RenderOptions | None:
"""
Return pre-content for the tag
"""
Expand Down
40 changes: 20 additions & 20 deletions meta/tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ html:
attributes:
lang:
doc: Language used by the document
type: Optional[str]
type: "str | None"

# Rename <del> tag as it is a reserved keyword in Python
del:
Expand All @@ -23,28 +23,28 @@ link:
attributes:
href:
doc: Location of the file being linked to
type: Optional[str]
type: "str | None"
rel:
doc: Kind of file being loaded (eg `"stylesheet"`)
type: Optional[str]
type: "str | None"

a:
base: StylableTag
attributes:
href:
doc: URL of page to link to
type: Optional[str]
type: "str | None"
target:
doc: Use "_blank" to open in a new tab
type: "Union[Literal['_self', '_blank', '_parent', '_top'], str, None]"
type: "Literal['_self', '_blank', '_parent', '_top'] | str | None"

script:
escape_children: false
attributes:
type:
doc: Type of script to use
default: "'text/javascript'"
type: Optional[str]
type: "str | None"
src: The location from which to load the script. If present, this will be used rather than the contents of the element.

style:
Expand All @@ -53,14 +53,14 @@ style:
type:
doc: Type of style to use
default: "'text/css'"
type: Optional[str]
type: "str | None"

form:
attributes:
method:
doc: The HTTP request method to use when submitting this form. In almost all cases, you'll want this to be POST.
default: "'post'"
type: "Optional[Literal['post', 'get']]"
type: "Literal['post', 'get'] | None"
action: The URL to request to when submitting this form. By default, requests will be sent to the same URL as the current page.

input:
Expand All @@ -80,7 +80,7 @@ th:
attributes:
scope:
doc: 'The area of the table that this heading applies to. Allowed values: `"col"`, `"row"`, `"colgroup"`, `"rowgroup"`'
type: "Optional[Literal['col', 'row', 'colgroup', 'rowgroup']]"
type: "Literal['col', 'row', 'colgroup', 'rowgroup'] | None"
colspan: The number of columns in the table that this heading spans.
rowspan: The number of rows in the table that this heading spans.

Expand Down Expand Up @@ -151,34 +151,34 @@ textarea:
attributes:
required:
doc: Whether the input is required to submit the form it is contained within.
type: "Optional[bool]"
type: "bool | None"
name: The name to use for this value when submitting the form.
rows:
doc: The number of rows (lines) to use in the text area. Value should be an integer, but given as type `str`.
type: "Optional[str]"
type: "str | None"
cols:
doc: The number of columns (length of each line) to use in the text area. Value should be an integer, but given as type `str`.
type: "Optional[str]"
type: "str | None"
placeholder: Placeholder text to use when the field is empty.
disabled:
doc: "Whether this option is disabled, meaning it cannot be selected, and will not be submitted with the form."
type: "Optional[bool]"
type: "bool | None"
maxlength: The maximum number of characters permitted in the textarea
wrap:
doc: How to perform word wrapping ("hard" or "soft")
type: "Union[Literal['hard', 'soft'], None]"
type: "Literal['hard', 'soft'] | None"
readonly:
doc: "Whether this option is read-only, meaning it cannot be modified"
type: "Optional[bool]"
type: "bool | None"

option:
attributes:
selected:
doc: "Whether this option is the default selection within the `select` element"
type: "Optional[bool]"
type: "bool | None"
disabled:
doc: "Whether this option is disabled, meaning it cannot be selected."
type: "Optional[bool]"
type: "bool | None"
value:
doc: "The value to use if this option is selected when submitting the form"

Expand All @@ -187,11 +187,11 @@ select:
attributes:
required:
doc: Whether the input is required to submit the form it is contained within.
type: "Optional[bool]"
type: "bool | None"
name: The name to use for this value when submitting the form.
disabled:
doc: "Whether this form element is disabled, meaning it cannot be selected, and will not be submitted with the form."
type: "Optional[bool]"
type: "bool | None"
multiple:
doc: "Whether multiple options can be simultaneously selected."
type: "Optional[bool]"
type: "bool | None"
12 changes: 6 additions & 6 deletions meta/templates/class_attrs_StylableTag.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def __init__(
self,
*children: ChildrenType,
{attr_args}
id: Optional[str] = None,
_class: Optional[str] = None,
style: Optional[str] = None,
id: str | None = None,
_class: str | None = None,
style: str | None = None,
**attributes: AttributeType,
) -> None:
"""
Expand All @@ -34,9 +34,9 @@ def __call__( # type: ignore
self,
*children: ChildrenType,
{attr_args}
id: Optional[str] = None,
_class: Optional[str] = None,
style: Optional[str] = None,
id: str | None = None,
_class: str | None = None,
style: str | None = None,
**attributes: AttributeType,
):
"""
Expand Down
2 changes: 1 addition & 1 deletion meta/templates/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

https://creativecommons.org/licenses/by-sa/2.5/
"""
from typing import Literal, Optional, Union
from typing import Literal

from ..__render_options import RenderOptions
from ..__tag_base import SelfClosingTag, Tag, WhitespaceSensitiveTag
Expand Down
4 changes: 2 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions pyhtml/__render_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"""

from dataclasses import asdict, dataclass
from typing import Optional

# While it could be cleaner (and far less-repetitive) to use a TypedDict and
# declare the partial options class as per
Expand Down Expand Up @@ -50,15 +49,15 @@ class RenderOptions:
PyHTML rendering options.
"""

indent: Optional[str] = None
indent: str | None = None
"""
String to add to indentation for non-inline child elements. For example,
to indent using a tab, you could use `'\\t'`.

Defaults to 2 spaces (`' '`).
"""

spacing: Optional[str] = None
spacing: str | None = None
"""
String to use for spacing between child elements. When this is set to
`'\\n'`, each child element will be placed on its own line, and indentation
Expand Down
4 changes: 2 additions & 2 deletions pyhtml/__tag_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Tag base class, including rendering logic
"""

from typing import Optional, TypeVar
from typing import TypeVar

from . import __util as util
from .__render_options import FullRenderOptions, RenderOptions
Expand Down Expand Up @@ -98,7 +98,7 @@ def _get_default_render_options(self) -> RenderOptions:
# By default, don't override any options
return RenderOptions()

def _get_tag_pre_content(self) -> Optional[str]:
def _get_tag_pre_content(self) -> str | None:
"""
Return "pre-content" for the tag.

Expand Down
Loading