Skip to content

Commit 10f9c14

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 359d93d commit 10f9c14

5 files changed

Lines changed: 21 additions & 21 deletions

File tree

markdown_it/common/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def replaceEntityPattern(match: str, name: str) -> str:
102102
if name in entities:
103103
return entities[name]
104104

105-
code: None | int = None
105+
code: int | None = None
106106
if pat := DIGITAL_ENTITY_BASE10_RE.fullmatch(name):
107107
code = int(pat.group(1), 10)
108108
elif pat := DIGITAL_ENTITY_BASE16_RE.fullmatch(name):

markdown_it/rules_block/fence.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ def make_fence_rule(
3737
closing_matcher: Callable[[int, int], bool]
3838
if exact_match:
3939
# closing code fence must have exactly the same number of markers as the opening one
40-
closing_matcher = lambda opening_len, closing_len: closing_len == opening_len # noqa: E731
40+
closing_matcher = lambda opening_len, closing_len: closing_len == opening_len
4141
else:
4242
# closing code fence must be at least as long as the opening one
43-
closing_matcher = lambda opening_len, closing_len: closing_len >= opening_len # noqa: E731
43+
closing_matcher = lambda opening_len, closing_len: closing_len >= opening_len
4444

4545
def _fence_rule(
4646
state: StateBlock, startLine: int, endLine: int, silent: bool

markdown_it/rules_core/smartquotes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def process_inlines(tokens: list[Token], state: StateCore) -> None:
5858

5959
# Find previous character,
6060
# default to space if it's the beginning of the line
61-
lastChar: None | int = 0x20
61+
lastChar: int | None = 0x20
6262

6363
if t.start(0) + lastIndex - 1 >= 0:
6464
lastChar = charCodeAt(text, t.start(0) + lastIndex - 1)
@@ -75,7 +75,7 @@ def process_inlines(tokens: list[Token], state: StateCore) -> None:
7575

7676
# Find next character,
7777
# default to space if it's the end of the line
78-
nextChar: None | int = 0x20
78+
nextChar: int | None = 0x20
7979

8080
if pos < maximum:
8181
nextChar = charCodeAt(text, pos)

markdown_it/token.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ def attrPush(self, attrData: tuple[str, str | int | float]) -> None:
9595
name, value = attrData
9696
self.attrSet(name, value)
9797

98-
def attrSet(self, name: str, value: str | int | float) -> None:
98+
def attrSet(self, name: str, value: str | float) -> None:
9999
"""Set `name` attribute to `value`. Override old value if exists."""
100100
self.attrs[name] = value
101101

102-
def attrGet(self, name: str) -> None | str | int | float:
102+
def attrGet(self, name: str) -> str | int | float | None:
103103
"""Get the value of attribute `name`, or null if it does not exist."""
104104
return self.attrs.get(name, None)
105105

markdown_it/tree.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import textwrap
1010
from typing import Any, NamedTuple, TypeVar, overload
1111

12+
from typing_extensions import Self
13+
1214
from .token import Token
1315

1416

@@ -84,13 +86,13 @@ def __getitem__(self: _NodeType, item: int) -> _NodeType: ...
8486
@overload
8587
def __getitem__(self: _NodeType, item: slice) -> list[_NodeType]: ...
8688

87-
def __getitem__(self: _NodeType, item: int | slice) -> _NodeType | list[_NodeType]:
89+
def __getitem__(self, item: int | slice) -> Self | list[Self]:
8890
return self.children[item]
8991

90-
def to_tokens(self: _NodeType) -> list[Token]:
92+
def to_tokens(self) -> list[Token]:
9193
"""Recover the linear token stream."""
9294

93-
def recursive_collect_tokens(node: _NodeType, token_list: list[Token]) -> None:
95+
def recursive_collect_tokens(node: Self, token_list: list[Token]) -> None:
9496
if node.type == "root":
9597
for child in node.children:
9698
recursive_collect_tokens(child, token_list)
@@ -108,19 +110,19 @@ def recursive_collect_tokens(node: _NodeType, token_list: list[Token]) -> None:
108110
return tokens
109111

110112
@property
111-
def children(self: _NodeType) -> list[_NodeType]:
113+
def children(self) -> list[Self]:
112114
return self._children
113115

114116
@children.setter
115-
def children(self: _NodeType, value: list[_NodeType]) -> None:
117+
def children(self, value: list[Self]) -> None:
116118
self._children = value
117119

118120
@property
119-
def parent(self: _NodeType) -> _NodeType | None:
121+
def parent(self) -> Self | None:
120122
return self._parent # type: ignore
121123

122124
@parent.setter
123-
def parent(self: _NodeType, value: _NodeType | None) -> None:
125+
def parent(self, value: Self | None) -> None:
124126
self._parent = value
125127

126128
@property
@@ -139,7 +141,7 @@ def is_nested(self) -> bool:
139141
return bool(self.nester_tokens)
140142

141143
@property
142-
def siblings(self: _NodeType) -> Sequence[_NodeType]:
144+
def siblings(self) -> Sequence[Self]:
143145
"""Get siblings of the node.
144146
145147
Gets the whole group of siblings, including self.
@@ -165,7 +167,7 @@ def type(self) -> str:
165167
return self.nester_tokens.opening.type.removesuffix("_open")
166168

167169
@property
168-
def next_sibling(self: _NodeType) -> _NodeType | None:
170+
def next_sibling(self) -> Self | None:
169171
"""Get the next node in the sequence of siblings.
170172
171173
Returns `None` if this is the last sibling.
@@ -176,7 +178,7 @@ def next_sibling(self: _NodeType) -> _NodeType | None:
176178
return None
177179

178180
@property
179-
def previous_sibling(self: _NodeType) -> _NodeType | None:
181+
def previous_sibling(self) -> Self | None:
180182
"""Get the previous node in the sequence of siblings.
181183
182184
Returns `None` if this is the first sibling.
@@ -241,9 +243,7 @@ def pretty(
241243
)
242244
return text
243245

244-
def walk(
245-
self: _NodeType, *, include_self: bool = True
246-
) -> Generator[_NodeType, None, None]:
246+
def walk(self, *, include_self: bool = True) -> Generator[Self, None, None]:
247247
"""Recursively yield all descendant nodes in the tree starting at self.
248248
249249
The order mimics the order of the underlying linear token
@@ -282,7 +282,7 @@ def attrs(self) -> dict[str, str | int | float]:
282282
"""Html attributes."""
283283
return self._attribute_token().attrs
284284

285-
def attrGet(self, name: str) -> None | str | int | float:
285+
def attrGet(self, name: str) -> str | int | float | None:
286286
"""Get the value of attribute `name`, or null if it does not exist."""
287287
return self._attribute_token().attrGet(name)
288288

0 commit comments

Comments
 (0)