Skip to content
This repository was archived by the owner on Oct 16, 2025. It is now read-only.

Commit 7053773

Browse files
committed
maintain: modernize and check types
1 parent c668baa commit 7053773

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

.pre-commit-config.yaml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.5.0
3+
rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0
44
hooks:
55
- id: end-of-file-fixer
66
- id: mixed-line-ending
77
- id: trailing-whitespace
88
- id: check-yaml
99
- id: check-toml
1010
- repo: https://github.com/pre-commit/pygrep-hooks
11-
rev: v1.10.0
11+
rev: 3a6eb0fadf60b3cccfd80bad9dbb6fae7e47b316 # frozen: v1.10.0
1212
hooks:
1313
- id: python-check-blanket-noqa
14-
- repo: https://github.com/timothycrosley/isort
15-
rev: 5.13.2
14+
- repo: https://github.com/PyCQA/isort
15+
rev: c235f5e450b4b84e58d114ed4c589cbf454175a3 # frozen: 5.13.2
1616
hooks:
1717
- id: isort
1818
- repo: https://github.com/psf/black
19-
rev: 24.2.0
19+
rev: 1b2427a2b785cc4aac97c19bb4b9a0de063f9547 # frozen: 24.10.0
2020
hooks:
2121
- id: black
2222
- repo: https://github.com/PyCQA/flake8
23-
rev: 7.0.0
23+
rev: e43806be3607110919eff72939fda031776e885a # frozen: 7.1.1
2424
hooks:
2525
- id: flake8
2626
additional_dependencies:
2727
- flake8-bugbear>=20.11.1
2828
- flake8-builtins>=1.5.3
2929
- flake8-comprehensions>=3.3.1
30+
- repo: https://github.com/pre-commit/mirrors-mypy
31+
rev: f56614daa94d5cd733d3b7004c5df9caad267b4a # frozen: v1.13.0
32+
hooks:
33+
- id: mypy
34+
args: ["--scripts-are-modules"]
35+
additional_dependencies:
36+
- mdformat
37+
files: ^src/mdformat_tables/.+\.py$

pyproject.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,22 @@ deps = ["pre-commit"]
8080
commands = [
8181
["pre-commit", "run", "--config", ".pre-commit-test.yaml", { replace = "posargs", default = ["--all-files", "--verbose", "--show-diff-on-failure"], extend = true }],
8282
]
83+
84+
85+
[tool.mypy]
86+
show_error_codes = true
87+
warn_unreachable = true
88+
warn_unused_ignores = true
89+
warn_redundant_casts = true
90+
warn_unused_configs = true
91+
# Disabling incremental mode is required for `warn_unused_configs = true` to work
92+
incremental = false
93+
disallow_untyped_defs = true
94+
check_untyped_defs = true
95+
strict_equality = true
96+
implicit_reexport = false
97+
no_implicit_optional = true
98+
99+
[[tool.mypy.overrides]]
100+
module = "wcwidth.*"
101+
ignore_missing_imports = true

src/mdformat_tables/plugin.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import argparse
2-
from typing import Iterable, List, Mapping, Sequence, Union
2+
from collections.abc import Iterable, Mapping, Sequence
33

44
from markdown_it import MarkdownIt
55
from mdformat.renderer import RenderContext, RenderTreeNode
@@ -40,8 +40,8 @@ def _center(text: str, width: int) -> str:
4040

4141
def _to_string(
4242
rows: Sequence[Sequence[str]], align: Sequence[Sequence[str]], widths: Sequence[int]
43-
) -> List[str]:
44-
def join_row(items: Union[Iterable[str], Sequence[str]]) -> str:
43+
) -> list[str]:
44+
def join_row(items: Iterable[str]) -> str:
4545
return "| " + " | ".join(items) + " |"
4646

4747
def format_delimiter_cell(index: int, align: str) -> str:
@@ -60,13 +60,13 @@ def format_delimiter_cell(index: int, align: str) -> str:
6060
delimiter = join_row(
6161
(format_delimiter_cell(i, al) for i, al in enumerate(align[0]))
6262
)
63-
rows = [
63+
joined_rows = (
6464
join_row(
6565
pad[_al](text, widths[i]) for i, (text, _al) in enumerate(zip(row, aligns))
6666
)
6767
for row, aligns in zip(rows[1:], align[1:])
68-
]
69-
return [header, delimiter, *rows]
68+
)
69+
return [header, delimiter, *joined_rows]
7070

7171

7272
def _render_table(node: RenderTreeNode, context: RenderContext) -> str:
@@ -80,8 +80,8 @@ def _render_table(node: RenderTreeNode, context: RenderContext) -> str:
8080
compact_tables_from_api = context.options["mdformat"].get("compact_tables")
8181
compact_tables = compact_tables_from_cli_or_toml or compact_tables_from_api
8282
# gather rendered cell content into row * column array
83-
rows: List[List[str]] = []
84-
align: List[List[str]] = []
83+
rows: list[list[str]] = []
84+
align: list[list[str]] = []
8585
for descendant in node.walk(include_self=False):
8686
if descendant.type == "tr":
8787
rows.append([])

0 commit comments

Comments
 (0)