Skip to content

Commit 6f84f65

Browse files
acharles7Charles Patel
and
Charles Patel
authored
Migrate mypy config to pyproject.toml (#3936)
Co-authored-by: Charles Patel <[email protected]>
1 parent 3bb9214 commit 6f84f65

12 files changed

+40
-54
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
_build
55
.DS_Store
66
.vscode
7+
.python-version
78
docs/_static/pypi.svg
89
.tox
910
__pycache__

.pre-commit-config.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ repos:
4343
hooks:
4444
- id: mypy
4545
exclude: ^docs/conf.py
46+
args: ["--config-file", "pyproject.toml"]
4647
additional_dependencies:
4748
- types-PyYAML
4849
- tomli >= 0.2.6, < 2.0.0
@@ -51,6 +52,10 @@ repos:
5152
- platformdirs >= 2.1.0
5253
- pytest
5354
- hypothesis
55+
- aiohttp >= 3.7.4
56+
- types-commonmark
57+
- urllib3
58+
- hypothesmith
5459

5560
- repo: https://github.com/pre-commit/mirrors-prettier
5661
rev: v3.0.3

mypy.ini

-46
This file was deleted.

pyproject.toml

+24
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ exclude = [
137137
# Compiled modules can't be run directly and that's a problem here:
138138
"/src/black/__main__.py",
139139
]
140+
mypy-args = ["--ignore-missing-imports"]
140141
options = { debug_level = "0" }
141142

142143
[tool.cibuildwheel]
@@ -223,3 +224,26 @@ omit = [
223224
]
224225
[tool.coverage.run]
225226
relative_files = true
227+
228+
[tool.mypy]
229+
# Specify the target platform details in config, so your developers are
230+
# free to run mypy on Windows, Linux, or macOS and get consistent
231+
# results.
232+
python_version = "3.8"
233+
mypy_path = "src"
234+
strict = true
235+
# Unreachable blocks have been an issue when compiling mypyc, let's try to avoid 'em in the first place.
236+
warn_unreachable = true
237+
implicit_reexport = true
238+
show_error_codes = true
239+
show_column_numbers = true
240+
241+
[[tool.mypy.overrides]]
242+
module = ["pathspec.*", "IPython.*", "colorama.*", "tokenize_rt.*", "uvloop.*", "_black_version.*"]
243+
ignore_missing_imports = true
244+
245+
# CI only checks src/, but in case users are running LSP or similar we explicitly ignore
246+
# errors in test data files.
247+
[[tool.mypy.overrides]]
248+
module = ["tests.data.*"]
249+
ignore_errors = true

scripts/check_pre_commit_rev_in_example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import commonmark
1616
import yaml
17-
from bs4 import BeautifulSoup
17+
from bs4 import BeautifulSoup # type: ignore[import]
1818

1919

2020
def main(changes: str, source_version_control: str) -> None:

scripts/check_version_in_basics_example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import sys
99

1010
import commonmark
11-
from bs4 import BeautifulSoup
11+
from bs4 import BeautifulSoup # type: ignore[import]
1212

1313

1414
def main(changes: str, the_basics: str) -> None:

scripts/diff_shades_gha_helper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def main() -> None:
119119
@main.command("config", help="Acquire run configuration and metadata.")
120120
@click.argument("event", type=click.Choice(["push", "pull_request"]))
121121
def config(event: Literal["push", "pull_request"]) -> None:
122-
import diff_shades
122+
import diff_shades # type: ignore[import]
123123

124124
if event == "push":
125125
jobs = [{"mode": "preview-changes", "force-flag": "--force-preview-style"}]

scripts/fuzz.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_idempotent_any_syntatically_valid_python(
8080
try:
8181
import sys
8282

83-
import atheris
83+
import atheris # type: ignore[import]
8484
except ImportError:
8585
pass
8686
else:

scripts/make_width_table.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from os.path import basename, dirname, join
2121
from typing import Iterable, Tuple
2222

23-
import wcwidth
23+
import wcwidth # type: ignore[import]
2424

2525

2626
def make_width_table() -> Iterable[Tuple[int, int, int]]:

src/blackd/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ def main(bind_host: str, bind_port: int) -> None:
7474
app = make_app()
7575
ver = black.__version__
7676
black.out(f"blackd version {ver} listening on {bind_host} port {bind_port}")
77-
web.run_app(app, host=bind_host, port=bind_port, handle_signals=True, print=None)
77+
# TODO: aiohttp had an incorrect annotation for `print` argument,
78+
# It'll be fixed once aiohttp releases that code
79+
web.run_app(app, host=bind_host, port=bind_port, handle_signals=True, print=None) # type: ignore[arg-type]
7880

7981

8082
def make_app() -> web.Application:

tests/optional.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from pytest import StashKey
2727
except ImportError:
2828
# pytest < 7
29-
from _pytest.store import StoreKey as StashKey # type: ignore[no-redef]
29+
from _pytest.store import StoreKey as StashKey # type: ignore[import, no-redef]
3030

3131
log = logging.getLogger(__name__)
3232

tests/test_blackd.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def unittest_run_loop(func, *args, **kwargs):
3131

3232

3333
@pytest.mark.blackd
34-
class BlackDTestCase(AioHTTPTestCase): # type: ignore[misc]
34+
class BlackDTestCase(AioHTTPTestCase):
3535
def test_blackd_main(self) -> None:
3636
with patch("blackd.web.run_app"):
3737
result = CliRunner().invoke(blackd.main, [])

0 commit comments

Comments
 (0)