Skip to content

Commit

Permalink
chore: replace importing of Match from typing
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed Jun 9, 2023
1 parent fc19c49 commit 3518067
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
26 changes: 13 additions & 13 deletions src/mistune/block_parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from typing import Optional, List, Tuple
from typing import Optional, List, Tuple, Match
from .util import (
unikey,
escape_url,
Expand Down Expand Up @@ -109,18 +109,18 @@ def __init__(
name: getattr(self, 'parse_' + name) for name in self.SPECIFICATION
}

def parse_blank_line(self, m: re.Match, state: BlockState) -> int:
def parse_blank_line(self, m: Match, state: BlockState) -> int:
"""Parse token for blank lines."""
state.append_token({'type': 'blank_line'})
return m.end()

def parse_thematic_break(self, m: re.Match, state: BlockState) -> int:
def parse_thematic_break(self, m: Match, state: BlockState) -> int:
"""Parse token for thematic break, e.g. ``<hr>`` tag in HTML."""
state.append_token({'type': 'thematic_break'})
# $ does not count '\n'
return m.end() + 1

def parse_indent_code(self, m: re.Match, state: BlockState) -> int:
def parse_indent_code(self, m: Match, state: BlockState) -> int:
"""Parse token for code block which is indented by 4 spaces."""
# it is a part of the paragraph
end_pos = state.append_paragraph()
Expand All @@ -134,7 +134,7 @@ def parse_indent_code(self, m: re.Match, state: BlockState) -> int:
state.append_token({'type': 'block_code', 'raw': code, 'style': 'indent'})
return m.end()

def parse_fenced_code(self, m: re.Match, state: BlockState) -> Optional[int]:
def parse_fenced_code(self, m: Match, state: BlockState) -> Optional[int]:
"""Parse token for fenced code block. A fenced code block is started with
3 or more backtick(`) or tilde(~).
Expand Down Expand Up @@ -182,7 +182,7 @@ def markdown(text):
state.append_token(token)
return end_pos

def parse_axt_heading(self, m: re.Match, state: BlockState) -> int:
def parse_axt_heading(self, m: Match, state: BlockState) -> int:
"""Parse token for AXT heading. An AXT heading is started with 1 to 6
symbol of ``#``."""
level = len(m.group('axt_1'))
Expand All @@ -195,7 +195,7 @@ def parse_axt_heading(self, m: re.Match, state: BlockState) -> int:
state.append_token(token)
return m.end() + 1

def parse_setex_heading(self, m: re.Match, state: BlockState) -> Optional[int]:
def parse_setex_heading(self, m: Match, state: BlockState) -> Optional[int]:
"""Parse token for setex style heading. A setex heading syntax looks like:
.. code-block:: markdown
Expand All @@ -216,7 +216,7 @@ def parse_setex_heading(self, m: re.Match, state: BlockState) -> Optional[int]:
if m:
return self.parse_method(m, state)

def parse_ref_link(self, m: re.Match, state: BlockState) -> Optional[int]:
def parse_ref_link(self, m: Match, state: BlockState) -> Optional[int]:
"""Parse link references and save the link information into ``state.env``.
Here is an example of a link reference:
Expand Down Expand Up @@ -282,7 +282,7 @@ def parse_ref_link(self, m: re.Match, state: BlockState) -> Optional[int]:
state.env['ref_links'][key] = data
return end_pos

def extract_block_quote(self, m: re.Match, state: BlockState) -> Tuple[str, int]:
def extract_block_quote(self, m: Match, state: BlockState) -> Tuple[str, int]:
"""Extract text and cursor end position of a block quote."""

# cleanup at first to detect if it is code block
Expand Down Expand Up @@ -349,7 +349,7 @@ def extract_block_quote(self, m: re.Match, state: BlockState) -> Tuple[str, int]
# treated as 4 spaces
return expand_tab(text), end_pos

def parse_block_quote(self, m: re.Match, state: BlockState) -> int:
def parse_block_quote(self, m: Match, state: BlockState) -> int:
"""Parse token for block quote. Here is an example of the syntax:
.. code-block:: markdown
Expand All @@ -374,14 +374,14 @@ def parse_block_quote(self, m: re.Match, state: BlockState) -> int:
state.append_token(token)
return state.cursor

def parse_list(self, m: re.Match, state: BlockState) -> int:
def parse_list(self, m: Match, state: BlockState) -> int:
"""Parse tokens for ordered and unordered list."""
return parse_list(self, m, state)

def parse_block_html(self, m: re.Match, state: BlockState) -> Optional[int]:
def parse_block_html(self, m: Match, state: BlockState) -> Optional[int]:
return self.parse_raw_html(m, state)

def parse_raw_html(self, m: re.Match, state: BlockState) -> Optional[int]:
def parse_raw_html(self, m: Match, state: BlockState) -> Optional[int]:
marker = m.group(0).strip()

# rule 2
Expand Down
22 changes: 11 additions & 11 deletions src/mistune/inline_parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from typing import Optional, List, Dict, Any
from typing import Optional, List, Dict, Any, Match
from .core import Parser, InlineState
from .util import (
escape,
Expand Down Expand Up @@ -107,7 +107,7 @@ def __init__(self, hard_wrap: bool=False):
name: getattr(self, 'parse_' + name) for name in self.rules
}

def parse_escape(self, m: re.Match, state: InlineState) -> int:
def parse_escape(self, m: Match, state: InlineState) -> int:
text = m.group(0)
text = unescape_char(text)
state.append_token({
Expand All @@ -116,7 +116,7 @@ def parse_escape(self, m: re.Match, state: InlineState) -> int:
})
return m.end()

def parse_link(self, m: re.Match, state: InlineState) -> Optional[int]:
def parse_link(self, m: Match, state: InlineState) -> Optional[int]:
pos = m.end()

marker = m.group(0)
Expand Down Expand Up @@ -200,7 +200,7 @@ def __parse_link_token(self, is_image, text, attrs, state):
}
return token

def parse_auto_link(self, m: re.Match, state: InlineState) -> int:
def parse_auto_link(self, m: Match, state: InlineState) -> int:
text = m.group(0)
pos = m.end()
if state.in_link:
Expand All @@ -211,7 +211,7 @@ def parse_auto_link(self, m: re.Match, state: InlineState) -> int:
self._add_auto_link(text, text, state)
return pos

def parse_auto_email(self, m: re.Match, state: InlineState) -> int:
def parse_auto_email(self, m: Match, state: InlineState) -> int:
text = m.group(0)
pos = m.end()
if state.in_link:
Expand All @@ -230,7 +230,7 @@ def _add_auto_link(self, url, text, state):
'attrs': {'url': escape_url(url)},
})

def parse_emphasis(self, m: re.Match, state: InlineState) -> int:
def parse_emphasis(self, m: Match, state: InlineState) -> int:
pos = m.end()

marker = m.group(0)
Expand Down Expand Up @@ -279,7 +279,7 @@ def parse_emphasis(self, m: re.Match, state: InlineState) -> int:
})
return end_pos

def parse_codespan(self, m: re.Match, state: InlineState) -> int:
def parse_codespan(self, m: Match, state: InlineState) -> int:
marker = m.group(0)
# require same marker with same length at end

Expand All @@ -301,15 +301,15 @@ def parse_codespan(self, m: re.Match, state: InlineState) -> int:
state.append_token({'type': 'text', 'raw': marker})
return pos

def parse_linebreak(self, m: re.Match, state: InlineState) -> int:
def parse_linebreak(self, m: Match, state: InlineState) -> int:
state.append_token({'type': 'linebreak'})
return m.end()

def parse_softbreak(self, m: re.Match, state: InlineState) -> int:
def parse_softbreak(self, m: Match, state: InlineState) -> int:
state.append_token({'type': 'softbreak'})
return m.end()

def parse_inline_html(self, m: re.Match, state: InlineState) -> int:
def parse_inline_html(self, m: Match, state: InlineState) -> int:
end_pos = m.end()
html = m.group(0)
state.append_token({'type': 'inline_html', 'raw': html})
Expand Down Expand Up @@ -351,7 +351,7 @@ def parse(self, state: InlineState) -> List[Dict[str, Any]]:
self.process_text(state.src[pos:], state)
return state.tokens

def precedence_scan(self, m: re.Match, state: InlineState, end_pos: int, rules=None):
def precedence_scan(self, m: Match, state: InlineState, end_pos: int, rules=None):
if rules is None:
rules = ['codespan', 'link', 'prec_auto_link', 'prec_inline_html']

Expand Down

0 comments on commit 3518067

Please sign in to comment.