Skip to content

Commit 89cbd56

Browse files
committed
chore: apply mypy and ruff
1 parent 70e9bcb commit 89cbd56

21 files changed

Lines changed: 57 additions & 85 deletions

benchmark/bench.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,7 @@ def get_markdown_parsers():
4040
parsers = {}
4141

4242
import mistune
43-
from mistune.directives import (
44-
RSTDirective,
45-
Admonition,
46-
TableOfContents,
47-
Include,
48-
)
43+
from mistune.directives import Admonition, Include, RSTDirective, TableOfContents
4944

5045
parsers[f"mistune ({mistune.__version__})"] = mistune.html
5146
parsers["mistune (core)"] = mistune.create_markdown(escape=False)
@@ -90,7 +85,8 @@ def get_markdown_parsers():
9085
pass
9186

9287
try:
93-
from markdown2 import Markdown, __version__ as m2v
88+
from markdown2 import Markdown
89+
from markdown2 import __version__ as m2v
9490

9591
markdowner = Markdown()
9692
parsers[f"markdown2 ({m2v})"] = markdowner.convert
@@ -105,7 +101,8 @@ def get_markdown_parsers():
105101
pass
106102

107103
try:
108-
from markdown_it import MarkdownIt, __version__ as mitv
104+
from markdown_it import MarkdownIt
105+
from markdown_it import __version__ as mitv
109106

110107
md = MarkdownIt()
111108
parsers[f"markdown_it ({mitv})"] = md.render

pyproject.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,25 @@ where = ["src"]
6969
mistune = ["py.typed"]
7070

7171
[tool.ruff]
72+
target-version = "py310"
7273
line-length = 120
7374

75+
[tool.ruff.lint]
76+
select = [
77+
"I",
78+
"F",
79+
]
80+
81+
[tool.ruff.lint.isort]
82+
split-on-trailing-comma=false
83+
84+
[tool.mypy]
85+
strict = true
86+
python_version = "3.10"
87+
files = ["src/mistune"]
88+
show_error_codes = true
89+
pretty = true
90+
7491
[tool.pytest.ini_options]
7592
pythonpath = ["src", "."]
7693
testpaths = ["tests"]

src/mistune/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
Documentation: https://mistune.lepture.com/
99
"""
1010

11-
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union, Literal
11+
from typing import Any, Dict, Iterable, List, Literal, Optional, Tuple, Union
12+
1213
from .block_parser import BlockParser
1314
from .core import BaseRenderer, BlockState, InlineState
1415
from .inline_parser import InlineParser

src/mistune/_inline/links.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44
from typing import TYPE_CHECKING, Dict, List, Match, Optional, Tuple
55

66
from ..core import InlineState
7-
from ..helpers import (
8-
parse_link as parse_link_destination,
9-
parse_link_label,
10-
parse_link_with_end,
11-
)
7+
from ..helpers import parse_link as parse_link_destination
8+
from ..helpers import parse_link_label, parse_link_with_end
129
from ..util import unikey
1310

1411
if TYPE_CHECKING:

src/mistune/block_parser.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1-
from bisect import bisect_left
21
import re
3-
from typing import Optional, List, Tuple, Match, Pattern, Set
42
import string
5-
from .util import (
6-
unikey,
7-
escape_url,
8-
expand_tab,
9-
expand_leading_tab,
10-
)
11-
from .core import Parser, BlockState
3+
from bisect import bisect_left
4+
from typing import List, Match, Optional, Pattern, Set, Tuple
5+
6+
from .core import BlockState, Parser
127
from .helpers import (
13-
LINK_LABEL,
14-
HTML_TAGNAME,
15-
HTML_ATTRIBUTES,
168
BLOCK_TAGS,
9+
HTML_ATTRIBUTES,
10+
HTML_TAGNAME,
11+
LINK_LABEL,
1712
PRE_TAGS,
18-
unescape_char,
1913
parse_link_href,
2014
parse_link_title,
15+
unescape_char,
2116
)
22-
from .list_parser import parse_list, LIST_PATTERN
17+
from .list_parser import LIST_PATTERN, parse_list
18+
from .util import escape_url, expand_leading_tab, expand_tab, unikey
2319

2420
DEFAULT_MAX_NESTED_LEVEL = 20
2521

src/mistune/directives/_base.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
import re
22
from abc import ABCMeta, abstractmethod
3-
from typing import (
4-
TYPE_CHECKING,
5-
Any,
6-
Callable,
7-
Dict,
8-
Iterable,
9-
List,
10-
Match,
11-
Optional,
12-
Tuple,
13-
Type,
14-
Union,
15-
)
3+
from typing import TYPE_CHECKING, Any, Callable, Dict, Iterable, List, Match, Optional, Tuple, Type, Union
164

175
if TYPE_CHECKING:
186
from ..block_parser import BlockParser

src/mistune/directives/admonition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import TYPE_CHECKING, Any, Dict, Match
2-
from ..util import escape as escape_text
32

3+
from ..util import escape as escape_text
44
from ._base import BaseDirective, DirectivePlugin
55

66
if TYPE_CHECKING:

src/mistune/inline_parser.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
from __future__ import annotations
22

33
import re
4-
from typing import (
5-
Any,
6-
Dict,
7-
List,
8-
Match,
9-
MutableMapping,
10-
Optional,
11-
Set,
12-
Tuple,
13-
)
4+
from typing import Any, Dict, List, Match, MutableMapping, Optional, Set, Tuple
145

156
from ._inline.emphasis import finalize_emphasis_tokens, is_entity_boundary
167
from ._inline.links import parse_link as parse_inline_link
178
from .core import InlineState, Parser
18-
from .helpers import (
19-
HTML_ATTRIBUTES,
20-
HTML_TAGNAME,
21-
PUNCTUATION,
22-
unescape_char,
23-
)
9+
from .helpers import HTML_ATTRIBUTES, HTML_TAGNAME, PUNCTUATION, unescape_char
2410
from .util import escape_url
2511

2612
_REGEX_META_CHARS = set(r"()[]{}?*+|.^$")

src/mistune/list_parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
import re
66
from dataclasses import dataclass
7-
from typing import TYPE_CHECKING, Any, Iterable, Optional, Match, Pattern, cast
7+
from typing import TYPE_CHECKING, Any, Iterable, Match, Optional, Pattern, cast
8+
89
from .util import strip_end
910

1011
if TYPE_CHECKING:

src/mistune/plugins/math.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import TYPE_CHECKING, Match
2+
23
from ..util import escape as escape_text
34

45
if TYPE_CHECKING:

0 commit comments

Comments
 (0)