From b8605eaa84f88e9cde4fe944f073eff9e7feaf89 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Fri, 30 Jun 2023 18:50:18 +0300 Subject: [PATCH 1/3] Check types with mypy --- .github/workflows/lint.yml | 6 ++++++ pyproject.toml | 31 +++++++++++++++++++++++++++++++ tox.ini | 7 +++++++ 3 files changed, 44 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c8fda7e7f..9069fc615 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -2,6 +2,9 @@ name: Lint on: [push, pull_request, workflow_dispatch] +env: + FORCE_COLOR: 1 + permissions: contents: read @@ -46,3 +49,6 @@ jobs: run: tox -e lint env: PRE_COMMIT_COLOR: always + + - name: Mypy + run: tox -e mypy diff --git a/pyproject.toml b/pyproject.toml index f9cea0612..63ee7d42d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -125,3 +125,34 @@ known-first-party = ["PIL"] [tool.pytest.ini_options] addopts = "-ra --color=yes" testpaths = ["Tests"] + +[tool.mypy] +python_version = "3.8" +pretty = true +disallow_any_generics = true +enable_error_code = "ignore-without-code" +extra_checks = true +follow_imports = "silent" +warn_redundant_casts = true +warn_unreachable = true +warn_unused_ignores = true +exclude = [ + '^src/PIL/_tkinter_finder.py$', + '^src/PIL/DdsImagePlugin.py$', + '^src/PIL/FpxImagePlugin.py$', + '^src/PIL/Image.py$', + '^src/PIL/ImageCms.py$', + '^src/PIL/ImageFile.py$', + '^src/PIL/ImageFont.py$', + '^src/PIL/ImageMath.py$', + '^src/PIL/ImageMorph.py$', + '^src/PIL/ImageQt.py$', + '^src/PIL/ImageShow.py$', + '^src/PIL/ImImagePlugin.py$', + '^src/PIL/MicImagePlugin.py$', + '^src/PIL/PdfParser.py$', + '^src/PIL/PyAccess.py$', + '^src/PIL/TiffImagePlugin.py$', + '^src/PIL/TiffTags.py$', + '^src/PIL/WebPImagePlugin.py$', +] diff --git a/tox.ini b/tox.ini index 5388ed243..7121df049 100644 --- a/tox.ini +++ b/tox.ini @@ -29,3 +29,10 @@ pass_env = commands = pre-commit run --all-files --show-diff-on-failure check-manifest + +[testenv:mypy] +skip_install = true +deps = + mypy==1.7.1 +commands = + mypy src {posargs} From 5db5d6617985747088d3a7bf385446675d20b90b Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Mon, 18 Dec 2023 15:42:22 +0200 Subject: [PATCH 2/3] Remove default 'line-length = 88' --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 63ee7d42d..a48a4fcc6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -94,7 +94,6 @@ test-command = "cd {project} && .github/workflows/wheels-test.sh" test-extras = "tests" [tool.ruff] -line-length = 88 select = [ "C4", # flake8-comprehensions "E", # pycodestyle errors From acc8f95f9b232b2b857de660dd6d9637b5617e1f Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 19 Dec 2023 11:25:42 +0200 Subject: [PATCH 3/3] Add NumPy to tox for mypy Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com> --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index 7121df049..034d89372 100644 --- a/tox.ini +++ b/tox.ini @@ -34,5 +34,6 @@ commands = skip_install = true deps = mypy==1.7.1 + numpy commands = mypy src {posargs}