Skip to content

Commit e303bd4

Browse files
authored
👌 IMPROVE: Make srcCharCode immutable (#114)
1 parent 8290faa commit e303bd4

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

markdown_it/parser_block.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Block-level tokenizer."""
22
import logging
3-
from typing import List, Optional
3+
from typing import List, Optional, Tuple
44

55
from .ruler import Ruler
66
from .token import Token
@@ -98,7 +98,7 @@ def parse(
9898
md,
9999
env,
100100
outTokens: List[Token],
101-
ords: Optional[List[int]] = None,
101+
ords: Optional[Tuple[int, ...]] = None,
102102
):
103103
"""Process input string and push block tokens into `outTokens`."""
104104
if not src:

markdown_it/ruler.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Ruler
2121
Iterable,
2222
List,
2323
Optional,
24+
Tuple,
2425
TYPE_CHECKING,
2526
Union,
2627
)
@@ -33,8 +34,9 @@ class Ruler
3334

3435

3536
class StateBase:
37+
srcCharCode: Tuple[int, ...]
38+
3639
def __init__(self, src: str, md: "MarkdownIt", env: AttrDict):
37-
self.srcCharCode: List[int] = []
3840
self.src = src
3941
self.env = env
4042
self.md = md
@@ -46,7 +48,9 @@ def src(self):
4648
@src.setter
4749
def src(self, value):
4850
self._src = value
49-
self.srcCharCode = [ord(c) for c in self.src] if self.src is not None else []
51+
self.srcCharCode = (
52+
tuple(ord(c) for c in self.src) if self.src is not None else ()
53+
)
5054

5155

5256
# The first positional arg is always a subtype of `StateBase`. Other

markdown_it/rules_block/state_block.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Optional
1+
from typing import List, Optional, Tuple
22

33
from ..token import Token
44
from ..ruler import StateBase
@@ -12,7 +12,7 @@ def __init__(
1212
md,
1313
env,
1414
tokens: List[Token],
15-
srcCharCode: Optional[List[int]] = None,
15+
srcCharCode: Optional[Tuple[int, ...]] = None,
1616
):
1717

1818
if srcCharCode is not None:

0 commit comments

Comments
 (0)