From dcf731e56502f3777fa217d8ea8325d7b617d6f1 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Fri, 20 Dec 2024 04:49:36 +0100 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=A7=AA=20Run=20MyPy=20against=20both?= =?UTF-8?q?=20Python=203.9=20and=203.13?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- check.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/check.sh b/check.sh index b65967596..3fb959ce8 100755 --- a/check.sh +++ b/check.sh @@ -57,13 +57,20 @@ echo "::group::Mypy" rm -f mypy_annotate.dat # Pipefail makes these pipelines fail if mypy does, even if mypy_annotate.py succeeds. set -o pipefail -mypy --show-error-end --platform linux | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Linux \ - || { echo "* Mypy (Linux) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; } +mypy --show-error-end --python-version=3.13 --platform linux | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Linux \ + || { echo "* Mypy (Linux, Python 3.13) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; } # Darwin tests FreeBSD too -mypy --show-error-end --platform darwin | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Mac \ - || { echo "* Mypy (Mac) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; } -mypy --show-error-end --platform win32 | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Windows \ - || { echo "* Mypy (Windows) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; } +mypy --show-error-end --python-version=3.13 --platform darwin | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Mac \ + || { echo "* Mypy (Mac, Python 3.13) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; } +mypy --show-error-end --python-version=3.13 --platform win32 | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Windows \ + || { echo "* Mypy (Windows, Python 3.13) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; } +mypy --show-error-end --python-version=3.9 --platform linux | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Linux \ + || { echo "* Mypy (Linux, Python 3.9) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; } +# Darwin tests FreeBSD too +mypy --show-error-end --python-version=3.9 --platform darwin | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Mac \ + || { echo "* Mypy (Mac, Python 3.9) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; } +mypy --show-error-end --python-version=3.9 --platform win32 | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Windows \ + || { echo "* Mypy (Windows, Python 3.9) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; } set +o pipefail # Re-display errors using Github's syntax, read out of mypy_annotate.dat python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat From 606f48094c35d4d47a1e71b589abf69d5ee138ed Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Fri, 20 Dec 2024 05:01:56 +0100 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=A7=AA=20Publish=20MyPy=20type=20cove?= =?UTF-8?q?rage=20to=20Codecov?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .codecov.yml | 30 ++++++++++++++++++++++++++---- .github/workflows/ci.yml | 20 +++++++++++++++----- README.rst | 4 ++-- check.sh | 12 ++++++------ test-requirements.in | 2 +- test-requirements.txt | 2 ++ 6 files changed, 52 insertions(+), 18 deletions(-) diff --git a/.codecov.yml b/.codecov.yml index fd577eb91..d0f90f969 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -6,7 +6,7 @@ codecov: notify: # This number needs to be changed whenever the number of runs in CI is changed. # Another option is codecov-cli: https://github.com/codecov/codecov-cli#send-notifications - after_n_builds: 31 + after_n_builds: 32 wait_for_ci: false notify_error: true # if uploads fail, replace cov comment with a comment with errors. require_ci_to_pass: false @@ -25,9 +25,31 @@ coverage: round: down range: 100..100 status: - project: - default: - target: 100% patch: default: target: 100% # require patches to be 100% + lib: + flags: + - pytest + typing: + flags: + - MyPy + project: + default: + target: 100% + lib: + flags: + - pytest + paths: + - src/ + target: 100% + tests: + flags: + - pytest + paths: + - tests/ + target: 100% + typing: + flags: + - MyPy + target: 91.79% diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7a3013261..bc9b83205 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -215,7 +215,7 @@ jobs: name: Windows (${{ matrix.python }}, ${{ matrix.arch }}${{ matrix.extra_name }}) # multiple flags is marked as an error in codecov UI, but is actually fine # https://github.com/codecov/feedback/issues/567 - flags: Windows,${{ matrix.python }} + flags: pytest,Windows,${{ matrix.python }} # this option cannot be set in .codecov.yml fail_ci_if_error: true @@ -278,8 +278,18 @@ jobs: with: directory: empty name: Ubuntu (${{ matrix.python }}${{ matrix.extra_name }}) - flags: Ubuntu,${{ matrix.python }} + flags: pytest,Ubuntu,${{ matrix.python }} fail_ci_if_error: true + - if: >- + always() + && matrix.check_formatting == '1' + uses: codecov/codecov-action@v5 + with: + disable_search: true + files: mypy-cov-*-py-*/* + flags: MyPy + fail_ci_if_error: true + name: MyPy type coverage macOS: name: 'macOS (${{ matrix.python }})' @@ -320,7 +330,7 @@ jobs: with: directory: empty name: macOS (${{ matrix.python }}) - flags: macOS,${{ matrix.python }} + flags: pytest,macOS,${{ matrix.python }} fail_ci_if_error: true # run CI on a musl linux @@ -356,7 +366,7 @@ jobs: with: directory: empty name: Alpine - flags: Alpine,${{ steps.get-version.outputs.version }} + flags: pytest,Alpine,${{ steps.get-version.outputs.version }} fail_ci_if_error: true Cython: @@ -416,7 +426,7 @@ jobs: uses: codecov/codecov-action@v5 with: name: Cython - flags: Cython,${{ steps.get-version.outputs.version }} + flags: pytest,Cython,${{ steps.get-version.outputs.version }} fail_ci_if_error: true # https://github.com/marketplace/actions/alls-green#why diff --git a/README.rst b/README.rst index e3620546a..dda27062d 100644 --- a/README.rst +++ b/README.rst @@ -18,8 +18,8 @@ :target: https://anaconda.org/conda-forge/trio :alt: Latest conda-forge version -.. image:: https://codecov.io/gh/python-trio/trio/branch/main/graph/badge.svg - :target: https://codecov.io/gh/python-trio/trio +.. image:: https://codecov.io/gh/python-trio/trio/graph/badge.svg?flag=pytest + :target: https://app.codecov.io/gh/python-trio/trio?flags[]=pytest :alt: Test coverage Trio – a friendly Python library for async concurrency and I/O diff --git a/check.sh b/check.sh index 3fb959ce8..75e2f907f 100755 --- a/check.sh +++ b/check.sh @@ -57,19 +57,19 @@ echo "::group::Mypy" rm -f mypy_annotate.dat # Pipefail makes these pipelines fail if mypy does, even if mypy_annotate.py succeeds. set -o pipefail -mypy --show-error-end --python-version=3.13 --platform linux | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Linux \ +mypy --show-error-end --python-version=3.13 --cobertura-xml-report=mypy-cov-linux-py-3.13 --platform linux | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Linux \ || { echo "* Mypy (Linux, Python 3.13) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; } # Darwin tests FreeBSD too -mypy --show-error-end --python-version=3.13 --platform darwin | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Mac \ +mypy --show-error-end --python-version=3.13 --cobertura-xml-report=mypy-cov-macos-py-3.13 --platform darwin | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Mac \ || { echo "* Mypy (Mac, Python 3.13) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; } -mypy --show-error-end --python-version=3.13 --platform win32 | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Windows \ +mypy --show-error-end --python-version=3.13 --cobertura-xml-report=mypy-cov-windows-py-3.13 --platform win32 | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Windows \ || { echo "* Mypy (Windows, Python 3.13) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; } -mypy --show-error-end --python-version=3.9 --platform linux | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Linux \ +mypy --show-error-end --python-version=3.9 --cobertura-xml-report=mypy-cov-linux-py-3.9 --platform linux | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Linux \ || { echo "* Mypy (Linux, Python 3.9) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; } # Darwin tests FreeBSD too -mypy --show-error-end --python-version=3.9 --platform darwin | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Mac \ +mypy --show-error-end --python-version=3.9 --cobertura-xml-report=mypy-cov-macos-py-3.9 --platform darwin | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Mac \ || { echo "* Mypy (Mac, Python 3.9) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; } -mypy --show-error-end --python-version=3.9 --platform win32 | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Windows \ +mypy --show-error-end --python-version=3.9 --cobertura-xml-report=mypy-cov-windows-py-3.9 --platform win32 | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Windows \ || { echo "* Mypy (Windows, Python 3.9) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; } set +o pipefail # Re-display errors using Github's syntax, read out of mypy_annotate.dat diff --git a/test-requirements.in b/test-requirements.in index 809e171e3..6fb2763f5 100644 --- a/test-requirements.in +++ b/test-requirements.in @@ -11,7 +11,7 @@ cryptography>=41.0.0 # cryptography<41 segfaults on pypy3.10 # Tools black; implementation_name == "cpython" -mypy # Would use mypy[faster-cache], but orjson has build issues on pypy +mypy[reports] # Would use mypy[faster-cache], but orjson has build issues on pypy orjson; implementation_name == "cpython" ruff >= 0.8.0 astor # code generation diff --git a/test-requirements.txt b/test-requirements.txt index 87b3c581e..7cb86972f 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -67,6 +67,8 @@ jedi==0.19.2 ; implementation_name == 'cpython' # via -r test-requirements.in jinja2==3.1.4 # via sphinx +lxml==5.3.0 + # via mypy markupsafe==3.0.2 # via jinja2 mccabe==0.7.0 From 185fb45548a4a55603de3b98d5dc3bdcf247c3d4 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Fri, 20 Dec 2024 05:29:24 +0100 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=A7=AATemporarily=20disable=20MyPy=20?= =?UTF-8?q?against=20Python=203.13?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- check.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/check.sh b/check.sh index 75e2f907f..de80ddaf1 100755 --- a/check.sh +++ b/check.sh @@ -57,13 +57,13 @@ echo "::group::Mypy" rm -f mypy_annotate.dat # Pipefail makes these pipelines fail if mypy does, even if mypy_annotate.py succeeds. set -o pipefail -mypy --show-error-end --python-version=3.13 --cobertura-xml-report=mypy-cov-linux-py-3.13 --platform linux | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Linux \ - || { echo "* Mypy (Linux, Python 3.13) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; } -# Darwin tests FreeBSD too -mypy --show-error-end --python-version=3.13 --cobertura-xml-report=mypy-cov-macos-py-3.13 --platform darwin | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Mac \ - || { echo "* Mypy (Mac, Python 3.13) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; } -mypy --show-error-end --python-version=3.13 --cobertura-xml-report=mypy-cov-windows-py-3.13 --platform win32 | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Windows \ - || { echo "* Mypy (Windows, Python 3.13) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; } +# mypy --show-error-end --python-version=3.13 --cobertura-xml-report=mypy-cov-linux-py-3.13 --platform linux | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Linux \ +# || { echo "* Mypy (Linux, Python 3.13) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; } +# # Darwin tests FreeBSD too +# mypy --show-error-end --python-version=3.13 --cobertura-xml-report=mypy-cov-macos-py-3.13 --platform darwin | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Mac \ +# || { echo "* Mypy (Mac, Python 3.13) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; } +# mypy --show-error-end --python-version=3.13 --cobertura-xml-report=mypy-cov-windows-py-3.13 --platform win32 | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Windows \ +# || { echo "* Mypy (Windows, Python 3.13) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; } mypy --show-error-end --python-version=3.9 --cobertura-xml-report=mypy-cov-linux-py-3.9 --platform linux | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Linux \ || { echo "* Mypy (Linux, Python 3.9) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; } # Darwin tests FreeBSD too From 2a8c841d16a918b9041547537ea6a1b613eeeb7f Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Mon, 23 Dec 2024 02:51:24 +0100 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=A7=AA=20Bring=20maximum=20strictness?= =?UTF-8?q?=20to=20MyPy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index bbc865ac6..a0853b32b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -176,9 +176,6 @@ fixture-parentheses = false python_version = "3.9" files = ["src/trio/", "docs/source/*.py"] -# Be flexible about dependencies that don't have stubs yet (like pytest) -ignore_missing_imports = true - # Be strict about use of Mypy local_partial_types = true warn_unused_ignores = true @@ -198,6 +195,26 @@ disallow_untyped_decorators = true disallow_untyped_defs = true check_untyped_defs = true +# Below are the originally missing strictness settings: +disallow_any_expr = true + +enable_error_code = [ + "ignore-without-code", +] + +extra_checks = true + +ignore_missing_imports = false + +no_implicit_reexport = true + +# `strict` will pick up any future strictness-related settings: +strict = true +strict_equality = true +strict_optional = true + +warn_no_return = true + [tool.pyright] pythonVersion = "3.9" reportUnnecessaryTypeIgnoreComment = true From 5847a66661e6f4f8a53ed0c5027ffbe5c69969a2 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Mon, 23 Dec 2024 02:57:43 +0100 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=A7=AA=20Type-check=20the=20`tests/`?= =?UTF-8?q?=20dir=20too?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a0853b32b..0fb794b6b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -174,7 +174,7 @@ fixture-parentheses = false [tool.mypy] python_version = "3.9" -files = ["src/trio/", "docs/source/*.py"] +files = ["src/trio/", "docs/source/*.py", "tests/"] # Be strict about use of Mypy local_partial_types = true