Skip to content

Commit a24ed2d

Browse files
authored
Adopt Mypy strict mode (#202)
1 parent cb78578 commit a24ed2d

File tree

6 files changed

+35
-22
lines changed

6 files changed

+35
-22
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ repos:
3939
rev: v0.982
4040
hooks:
4141
- id: mypy
42+
additional_dependencies:
43+
- black==22.12.0

blacken_docs.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from typing import Sequence
1111

1212
import black
13+
from black.const import DEFAULT_LINE_LENGTH
14+
from black.mode import TargetVersion
1315

1416

1517
MD_RE = re.compile(
@@ -117,7 +119,7 @@ def _rst_match(match: Match[str]) -> str:
117119

118120
def _pycon_match(match: Match[str]) -> str:
119121
code = ''
120-
fragment = None
122+
fragment: str | None = None
121123

122124
def finish_fragment() -> None:
123125
nonlocal code
@@ -216,15 +218,15 @@ def format_file(
216218
def main(argv: Sequence[str] | None = None) -> int:
217219
parser = argparse.ArgumentParser()
218220
parser.add_argument(
219-
'-l', '--line-length', type=int, default=black.DEFAULT_LINE_LENGTH,
221+
'-l', '--line-length', type=int, default=DEFAULT_LINE_LENGTH,
220222
)
221223
parser.add_argument(
222224
'-t',
223225
'--target-version',
224226
action='append',
225-
type=lambda v: black.TargetVersion[v.upper()],
227+
type=lambda v: TargetVersion[v.upper()],
226228
default=[],
227-
help=f'choices: {[v.name.lower() for v in black.TargetVersion]}',
229+
help=f'choices: {[v.name.lower() for v in TargetVersion]}',
228230
dest='target_versions',
229231
)
230232
parser.add_argument(

pyproject.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[build-system]
2+
requires = ["setuptools"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[tool.black]
6+
target-version = ['py37']
7+
8+
[tool.mypy]
9+
mypy_path = "src/"
10+
namespace_packages = false
11+
show_error_codes = true
12+
strict = true
13+
warn_unreachable = true
14+
15+
[[tool.mypy.overrides]]
16+
module = "tests.*"
17+
allow_untyped_defs = true
18+
19+
[tool.pytest.ini_options]
20+
addopts = """\
21+
--strict-config
22+
--strict-markers
23+
"""

requirements/requirements.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
black
1+
black>=22.1.0
22
coverage
33
pytest
44
pytest-randomly

setup.cfg

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ classifiers =
2121
[options]
2222
py_modules = blacken_docs
2323
install_requires =
24-
black>=19.3b0
24+
black>=22.1.0
2525
python_requires = >=3.7
2626

2727
[options.entry_points]
@@ -40,18 +40,3 @@ source =
4040

4141
[coverage:report]
4242
show_missing = True
43-
44-
[mypy]
45-
check_untyped_defs = true
46-
disallow_any_generics = true
47-
disallow_incomplete_defs = true
48-
disallow_untyped_defs = true
49-
no_implicit_optional = true
50-
warn_redundant_casts = true
51-
warn_unused_ignores = true
52-
53-
[mypy-testing.*]
54-
disallow_untyped_defs = false
55-
56-
[mypy-tests.*]
57-
disallow_untyped_defs = false

tests/blacken_docs_test.py

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

33
import black
4+
from black.const import DEFAULT_LINE_LENGTH
45

56
import blacken_docs
67

78

8-
BLACK_MODE = black.FileMode(line_length=black.DEFAULT_LINE_LENGTH)
9+
BLACK_MODE = black.FileMode(line_length=DEFAULT_LINE_LENGTH)
910

1011

1112
def test_format_src_trivial():

0 commit comments

Comments
 (0)