From 192e8268685c4839583cee808387a81b51a66d2e Mon Sep 17 00:00:00 2001 From: Jan-Eric Nitschke <47750513+JanEricNitschke@users.noreply.github.com> Date: Sat, 29 Jun 2024 20:40:45 +0200 Subject: [PATCH 1/3] Setup optional CI jobs using pyright strict mode --- .github/workflows/optional.yml | 17 +++++++++++++++++ docs/tests.md | 1 + pyproject.toml | 4 ++++ pyrightconfig-strict.json | 8 ++++++++ scripts/test/_step.py | 4 ++++ scripts/test/run.py | 5 +++++ 6 files changed, 39 insertions(+) create mode 100644 pyrightconfig-strict.json diff --git a/.github/workflows/optional.yml b/.github/workflows/optional.yml index fac7a9697..43203986f 100644 --- a/.github/workflows/optional.yml +++ b/.github/workflows/optional.yml @@ -4,6 +4,7 @@ on: push: branches: - main + - strict-ci workflow_dispatch: jobs: @@ -38,3 +39,19 @@ jobs: - name: Run mypy tests with mypy nightly run: poetry run poe mypy --mypy_nightly + + pyright_strict: + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - uses: actions/checkout@v3 + + - name: Install project dependencies + uses: ./.github/setup + with: + os: ubuntu-latest + python-version: '3.11' + + - name: Run pyright tests with full strict mode + run: poetry run poe pyright_strict diff --git a/docs/tests.md b/docs/tests.md index 1314a4596..fdf2dd5e8 100644 --- a/docs/tests.md +++ b/docs/tests.md @@ -18,4 +18,5 @@ The following tests are **optional**. Some of them are run by the CI but it is o - Run pytest against pandas nightly: `poe pytest --nightly` - Use mypy nightly to validate the annotations: `poe mypy --mypy_nightly` +- Use pyright in full strict mode: `poe pyright_strict` - Run stubtest to compare the installed pandas-stubs against pandas (this will fail): `poe stubtest`. If you have created an allowlist to ignore certain errors: `poe stubtest path_to_the_allow_list` diff --git a/pyproject.toml b/pyproject.toml index b6889888d..71c22ca55 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -109,6 +109,10 @@ script = "scripts.test:test(dist=True, type_checker='mypy')" help = "Run pyright on 'tests' (using the local stubs) and on the local stubs" script = "scripts.test.run:pyright_src" +[tool.poe.tasks.pyright_strict] +help = "Run pyright on 'tests' (using the local stubs) and on the local stubs in full strict mode" +script = "scripts.test.run:pyright_src_strict" + [tool.poe.tasks.pyright_dist] help = "Run pyright on 'tests' using the installed stubs" script = "scripts.test:test(dist=True, type_checker='pyright')" diff --git a/pyrightconfig-strict.json b/pyrightconfig-strict.json new file mode 100644 index 000000000..7953b6beb --- /dev/null +++ b/pyrightconfig-strict.json @@ -0,0 +1,8 @@ +{ + "typeCheckingMode": "strict", + "stubPath": ".", + "include": ["tests", "pandas-stubs"], + "reportUnnecessaryTypeIgnoreComment": true, + "reportMissingModuleSource": true, + "useLibraryCodeForTypes": false +} diff --git a/scripts/test/_step.py b/scripts/test/_step.py index 882a9a468..5bd077174 100644 --- a/scripts/test/_step.py +++ b/scripts/test/_step.py @@ -9,6 +9,10 @@ name="Run pyright on 'tests' (using the local stubs) and on the local stubs", run=run.pyright_src, ) +pyright_src_strict = Step( + name="Run pyright on 'tests' (using the local stubs) and on the local stubs in full strict mode", + run=run.pyright_src_strict, +) pytest = Step(name="Run pytest", run=run.pytest) style = Step(name="Run pre-commit", run=run.style) build_dist = Step(name="Build pandas-stubs", run=run.build_dist) diff --git a/scripts/test/run.py b/scripts/test/run.py index c30395da9..24ca194c5 100644 --- a/scripts/test/run.py +++ b/scripts/test/run.py @@ -15,6 +15,11 @@ def pyright_src(): subprocess.run(cmd, check=True) +def pyright_src_strict(): + cmd = ["pyright", "--project", "pyrightconfig-strict.json"] + subprocess.run(cmd, check=True) + + def pytest(): cmd = ["pytest", "--cache-clear"] subprocess.run(cmd, check=True) From 7756bd4dd217120a8cb2cacb88abd8b2865cf71e Mon Sep 17 00:00:00 2001 From: Jan-Eric Nitschke <47750513+JanEricNitschke@users.noreply.github.com> Date: Sat, 29 Jun 2024 20:42:39 +0200 Subject: [PATCH 2/3] Revert temporary test CI settings --- .github/workflows/optional.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/optional.yml b/.github/workflows/optional.yml index 43203986f..4cbeccc03 100644 --- a/.github/workflows/optional.yml +++ b/.github/workflows/optional.yml @@ -4,7 +4,6 @@ on: push: branches: - main - - strict-ci workflow_dispatch: jobs: From 561ffd0ee976ca383654db6ea22c76e443404e94 Mon Sep 17 00:00:00 2001 From: Jan-Eric Nitschke <47750513+JanEricNitschke@users.noreply.github.com> Date: Sat, 29 Jun 2024 20:44:58 +0200 Subject: [PATCH 3/3] Fix pyright strict config --- pyrightconfig-strict.json | 1 + 1 file changed, 1 insertion(+) diff --git a/pyrightconfig-strict.json b/pyrightconfig-strict.json index 7953b6beb..4d5e9b0ed 100644 --- a/pyrightconfig-strict.json +++ b/pyrightconfig-strict.json @@ -2,6 +2,7 @@ "typeCheckingMode": "strict", "stubPath": ".", "include": ["tests", "pandas-stubs"], + "enableTypeIgnoreComments": false, "reportUnnecessaryTypeIgnoreComment": true, "reportMissingModuleSource": true, "useLibraryCodeForTypes": false