Skip to content

Commit 4a0c6cd

Browse files
Merge pull request #111 from COMP1010UNSW/maddy-revamp-pyproject
Redo pyproject.toml to use Poetry v2 structure
2 parents e8d3e8a + 0f9ae72 commit 4a0c6cd

File tree

14 files changed

+444
-446
lines changed

14 files changed

+444
-446
lines changed

meta/generate_tag_defs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def _escape_children(self) -> bool:
2121
"""
2222

2323
GET_PRE_CONTENT = """
24-
def _get_tag_pre_content(self) -> Optional[str]:
24+
def _get_tag_pre_content(self) -> str | None:
2525
return {}
2626
"""
2727

meta/scrape_tags.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import sys
1111
from collections.abc import Iterator
1212
from dataclasses import dataclass
13-
from typing import Any, Optional, TypedDict, Union
13+
from typing import Any, TypedDict
1414

1515
import requests
1616
import yaml
@@ -42,7 +42,7 @@
4242
"""
4343

4444

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

5656

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

6868

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

8080

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

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

143143
base: NotRequired[str]
@@ -175,7 +175,7 @@ class Attr:
175175
Name of the attribute
176176
"""
177177

178-
doc: Optional[str]
178+
doc: str | None
179179
"""
180180
Documentation of the attribute if applicable
181181
"""
@@ -185,7 +185,7 @@ class Attr:
185185
Type to accept for the attribute
186186
"""
187187

188-
default: Optional[Any]
188+
default: Any | None
189189
"""
190190
Default value for the attribute
191191
"""
@@ -227,12 +227,12 @@ class TagInfo:
227227
List of attributes and their documentation.
228228
"""
229229

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

235-
render_options: Optional[RenderOptions]
235+
render_options: RenderOptions | None
236236
"""
237237
Render options
238238
"""
@@ -419,8 +419,8 @@ def attr_entries_to_object(tags: TagsYaml, tag_name: str) -> list[Attr]:
419419
attrs = []
420420
for name, value in tag_data["attributes"].items():
421421
if isinstance(value, str):
422-
doc: Optional[str] = value
423-
default: Optional[str] = None
422+
doc: str | None = value
423+
default: str | None = None
424424
type = "AttributeType"
425425
else:
426426
doc = value.get("doc")
@@ -479,7 +479,7 @@ def get_tag_escape_children(tags: TagsYaml, tag_name: str) -> bool:
479479
return tag.get("escape_children", True)
480480

481481

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

492492
def get_tag_render_options(
493493
tags: TagsYaml, tag_name: str
494-
) -> Optional[RenderOptions]:
494+
) -> RenderOptions | None:
495495
"""
496496
Return pre-content for the tag
497497
"""

meta/tags.yml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ html:
66
attributes:
77
lang:
88
doc: Language used by the document
9-
type: Optional[str]
9+
type: "str | None"
1010

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

3131
a:
3232
base: StylableTag
3333
attributes:
3434
href:
3535
doc: URL of page to link to
36-
type: Optional[str]
36+
type: "str | None"
3737
target:
3838
doc: Use "_blank" to open in a new tab
39-
type: "Union[Literal['_self', '_blank', '_parent', '_top'], str, None]"
39+
type: "Literal['_self', '_blank', '_parent', '_top'] | str | None"
4040

4141
script:
4242
escape_children: false
4343
attributes:
4444
type:
4545
doc: Type of script to use
4646
default: "'text/javascript'"
47-
type: Optional[str]
47+
type: "str | None"
4848
src: The location from which to load the script. If present, this will be used rather than the contents of the element.
4949

5050
style:
@@ -53,14 +53,14 @@ style:
5353
type:
5454
doc: Type of style to use
5555
default: "'text/css'"
56-
type: Optional[str]
56+
type: "str | None"
5757

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

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

@@ -151,34 +151,34 @@ textarea:
151151
attributes:
152152
required:
153153
doc: Whether the input is required to submit the form it is contained within.
154-
type: "Optional[bool]"
154+
type: "bool | None"
155155
name: The name to use for this value when submitting the form.
156156
rows:
157157
doc: The number of rows (lines) to use in the text area. Value should be an integer, but given as type `str`.
158-
type: "Optional[str]"
158+
type: "str | None"
159159
cols:
160160
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`.
161-
type: "Optional[str]"
161+
type: "str | None"
162162
placeholder: Placeholder text to use when the field is empty.
163163
disabled:
164164
doc: "Whether this option is disabled, meaning it cannot be selected, and will not be submitted with the form."
165-
type: "Optional[bool]"
165+
type: "bool | None"
166166
maxlength: The maximum number of characters permitted in the textarea
167167
wrap:
168168
doc: How to perform word wrapping ("hard" or "soft")
169-
type: "Union[Literal['hard', 'soft'], None]"
169+
type: "Literal['hard', 'soft'] | None"
170170
readonly:
171171
doc: "Whether this option is read-only, meaning it cannot be modified"
172-
type: "Optional[bool]"
172+
type: "bool | None"
173173

174174
option:
175175
attributes:
176176
selected:
177177
doc: "Whether this option is the default selection within the `select` element"
178-
type: "Optional[bool]"
178+
type: "bool | None"
179179
disabled:
180180
doc: "Whether this option is disabled, meaning it cannot be selected."
181-
type: "Optional[bool]"
181+
type: "bool | None"
182182
value:
183183
doc: "The value to use if this option is selected when submitting the form"
184184

@@ -187,11 +187,11 @@ select:
187187
attributes:
188188
required:
189189
doc: Whether the input is required to submit the form it is contained within.
190-
type: "Optional[bool]"
190+
type: "bool | None"
191191
name: The name to use for this value when submitting the form.
192192
disabled:
193193
doc: "Whether this form element is disabled, meaning it cannot be selected, and will not be submitted with the form."
194-
type: "Optional[bool]"
194+
type: "bool | None"
195195
multiple:
196196
doc: "Whether multiple options can be simultaneously selected."
197-
type: "Optional[bool]"
197+
type: "bool | None"

meta/templates/class_attrs_StylableTag.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ def __init__(
1010
self,
1111
*children: ChildrenType,
1212
{attr_args}
13-
id: Optional[str] = None,
14-
_class: Optional[str] = None,
15-
style: Optional[str] = None,
13+
id: str | None = None,
14+
_class: str | None = None,
15+
style: str | None = None,
1616
**attributes: AttributeType,
1717
) -> None:
1818
"""
@@ -34,9 +34,9 @@ def __call__( # type: ignore
3434
self,
3535
*children: ChildrenType,
3636
{attr_args}
37-
id: Optional[str] = None,
38-
_class: Optional[str] = None,
39-
style: Optional[str] = None,
37+
id: str | None = None,
38+
_class: str | None = None,
39+
style: str | None = None,
4040
**attributes: AttributeType,
4141
):
4242
"""

meta/templates/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
https://creativecommons.org/licenses/by-sa/2.5/
99
"""
10-
from typing import Literal, Optional, Union
10+
from typing import Literal
1111

1212
from ..__render_options import RenderOptions
1313
from ..__tag_base import SelfClosingTag, Tag, WhitespaceSensitiveTag

poetry.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyhtml/__render_options.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"""
66

77
from dataclasses import asdict, dataclass
8-
from typing import Optional
98

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

53-
indent: Optional[str] = None
52+
indent: str | None = None
5453
"""
5554
String to add to indentation for non-inline child elements. For example,
5655
to indent using a tab, you could use `'\\t'`.
5756
5857
Defaults to 2 spaces (`' '`).
5958
"""
6059

61-
spacing: Optional[str] = None
60+
spacing: str | None = None
6261
"""
6362
String to use for spacing between child elements. When this is set to
6463
`'\\n'`, each child element will be placed on its own line, and indentation

pyhtml/__tag_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Tag base class, including rendering logic
55
"""
66

7-
from typing import Optional, TypeVar
7+
from typing import TypeVar
88

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

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

0 commit comments

Comments
 (0)