Skip to content

Commit ce171a0

Browse files
committed
Fix issues flagged by ty/pyrefly
1 parent 61e95c8 commit ce171a0

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

src/wagtail_tinytableblock/blocks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def js_args(self, block) -> list:
7474

7575
@cached_property
7676
def media(self) -> Media:
77-
field_media = super().media
77+
field_media: Media = super().media
7878
js = [
7979
*field_media._js, # pylint: disable=protected-access
8080
"wagtail_tinytableblock/js/vendor/tinymce/tinymce.min.js",
@@ -97,7 +97,7 @@ def __init__(
9797
*,
9898
allow_links: bool = False,
9999
enable_context_menu: bool = False,
100-
**kwargs
100+
**kwargs,
101101
) -> None:
102102
if local_blocks is None:
103103
local_blocks = ()

src/wagtail_tinytableblock/utils.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def sanitise_html(content: str, *, allow_links: bool = False) -> str:
3333
return sanitizer.clean(unescape(content)) # pylint: disable=no-member
3434

3535

36-
STYLE_PROPS_PATTERN = re.compile(r"([^\s:;]+)\s*:\s*([^;]+)")
36+
STYLE_PROPS_PATTERN: re.Pattern[str] = re.compile(r"([^\s:;]+)\s*:\s*([^;]+)")
3737

3838

3939
def clean_style_attributes(table: "Tag") -> None:
@@ -52,7 +52,12 @@ def clean_style_attributes(table: "Tag") -> None:
5252
if "style" not in tag.attrs:
5353
continue
5454

55-
matches = STYLE_PROPS_PATTERN.findall(tag["style"])
55+
style: str = (
56+
"; ".join(tag["style"])
57+
if not isinstance(tag["style"], str)
58+
else tag["style"]
59+
)
60+
matches = STYLE_PROPS_PATTERN.findall(style)
5661
filtered_styles = []
5762
for prop, value in matches:
5863
prop = prop.strip()
@@ -67,18 +72,20 @@ def clean_style_attributes(table: "Tag") -> None:
6772

6873
def get_cell_data(cell: "Tag", forced_type: Cell | None = None) -> dict[str, str | int]:
6974
value = "".join(str(child) for child in cell.children)
70-
cell_data = {"value": value, "type": forced_type or cell.name}
75+
cell_data: dict[str, str | int] = {"value": value, "type": forced_type or cell.name}
7176

72-
if (rowspan := int(cell.get("rowspan", 1))) > 1:
77+
if (rowspan := int(str(cell.get("rowspan", "1")))) > 1:
7378
cell_data["rowspan"] = rowspan
74-
if (colspan := int(cell.get("colspan", 1))) > 1:
79+
if (colspan := int(str(cell.get("colspan", "1")))) > 1:
7580
cell_data["colspan"] = colspan
7681
if scope := cell.get("scope"):
77-
cell_data["scope"] = scope
82+
cell_data["scope"] = str(scope)
7883
if align := cell.get("align"):
79-
cell_data["align"] = align
84+
cell_data["align"] = str(align)
8085

8186
if style := cell.get("style"):
87+
if not isinstance(style, str):
88+
style = "; ".join(style)
8289
matches = dict(STYLE_PROPS_PATTERN.findall(style))
8390
if width := matches.get("width"):
8491
cell_data["width"] = width

0 commit comments

Comments
 (0)