Skip to content

Commit 5dd2474

Browse files
committed
Replace asserts with check.isinstance and simplify type hints and predicates
Update blockquote kind function to use PEP 604 union syntax, switch runtime type checks to omlish.check, streamline Unicode punctuation detection, and clarify the HTML block start loop condition.
1 parent 222fa2c commit 5dd2474

5 files changed

Lines changed: 8 additions & 5 deletions

File tree

omxtra/text/pdcmark/blocks/machine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ def _close_container_event(self, c: OpenContainer, end_offset: int) -> Event:
964964
}
965965

966966

967-
def _scan_blockquote_kind_consuming(ls: LineStart) -> 'BlockQuoteKind | None':
967+
def _scan_blockquote_kind_consuming(ls: LineStart) -> BlockQuoteKind | None:
968968
"""
969969
Look at the remainder of the line for `[!NAME]` followed only by whitespace through EOL. On match, consume the
970970
marker text and return the kind. Otherwise leave `ls` unchanged.

omxtra/text/pdcmark/inlines/emphasis.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
Cf. pulldown-cmark/src/parse.rs::{handle_emphasis_and_hard_break, InlineStack} — same algorithm. The pulldown version
1010
operates on its block tree in place; we operate on a fresh list.
1111
"""
12+
from omlish import check
13+
1214
from .nodes import DelimNode
1315
from .nodes import EmphasisGroup
1416
from .nodes import InlineNode
@@ -42,7 +44,7 @@ def resolve_emphasis(nodes: list[InlineNode]) -> list[InlineNode]:
4244
if match_s is not None:
4345
opener_i = delim_stack[match_s]
4446
opener = nodes[opener_i]
45-
assert isinstance(opener, DelimNode)
47+
check.isinstance(opener, DelimNode)
4648

4749
# GFM strikethrough: `~` and `~~` both produce <del>; longer runs (`~~~+`) don't pair at all. Equivalent
4850
# to the GFM "tilde must be ≤ 2 chars" rule.

omxtra/text/pdcmark/inlines/links.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- Resolution order for a closer: inline → reference → collapsed → shortcut. Whichever first succeeds wins. None
1515
succeeded? The opener / closer revert to text.
1616
"""
17+
from omlish import check
1718
from omlish import dataclasses as dc
1819

1920
from ..blocks.refdefs import LinkDef
@@ -95,7 +96,7 @@ def resolve_links(
9596
match_s = len(stack) - 1
9697
entry = stack[match_s]
9798
opener = nodes[entry.node_index]
98-
assert isinstance(opener, LinkOpenNode)
99+
check.isinstance(opener, LinkOpenNode)
99100

100101
# Inner children = nodes strictly between opener and closer.
101102
children = nodes[entry.node_index + 1:i]

omxtra/text/pdcmark/inlines/tokenize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def _is_unicode_punct(c: str) -> bool:
398398
if c in '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~':
399399
return True
400400
cat = unicodedata.category(c)
401-
return cat.startswith('P') or cat.startswith('S')
401+
return cat.startswith(('P', 'S'))
402402

403403

404404
def _line_index_at_newline(joined: _Joined, pos: int) -> int | None:

omxtra/text/pdcmark/scanning/htmlblocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def scan_html_block_start(line: str) -> HtmlBlockStart | None:
143143
if is_close:
144144
i += 1
145145
j = i
146-
while j < n and (line[j].isalnum() and line[j].isascii() or (j > i and line[j] in '0123456789')):
146+
while j < n and ((line[j].isalnum() and line[j].isascii()) or (j > i and line[j] in '0123456789')):
147147
j += 1
148148
if j == i:
149149
return None

0 commit comments

Comments
 (0)