Skip to content

Commit 882a591

Browse files
authored
Switch from mypy to pyright for static type checking (#23)
* Switch from mypy to pyright for static type checking * Remove script version of pyright
1 parent b14b7d1 commit 882a591

File tree

7 files changed

+51
-80
lines changed

7 files changed

+51
-80
lines changed

.github/workflows/lint.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,19 @@ jobs:
1919
python-version: "3.13"
2020
- name: Install dependencies
2121
run: |
22+
python -m venv .venv/
23+
source .venv/bin/activate
2224
python -m pip install --upgrade pip
2325
python -m pip install --group ci
2426
python -m pip install .
25-
- name: Run ruff check
26-
run: ruff check --output-format=github src/ tests/ examples/
27-
- name: Run ruff format
28-
run: ruff format --diff src/ tests/ examples/
29-
- name: Run mypy
30-
run: python -m mypy src/ tests/ examples/
27+
- name: Permanently activate venv
28+
run: echo "$PWD/.venv/bin" >> $GITHUB_PATH
29+
- name: Run ruff check linter
30+
run: |
31+
ruff check --output-format=github src/ tests/ examples/
32+
- name: Run ruff format formatter
33+
run: |
34+
ruff format --diff src/ tests/ examples/
35+
- uses: jakebailey/pyright-action@v2
36+
with:
37+
pylance-version: latest-release

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ repos:
2020
- id: ruff-format
2121
args: [src/, tests/, examples/]
2222

23-
- repo: https://github.com/pre-commit/mirrors-mypy
24-
rev: v1.17.1
23+
- repo: https://github.com/RobertCraigie/pyright-python
24+
rev: v1.1.404
2525
hooks:
26-
- id: mypy
27-
additional_dependencies: [pydantic>=2.0, pyplugs>=0.5.4 , pytest>=8.4.1, rich>=14.1.0, tomli-w>=1.2.0]
26+
- id: pyright
27+
args: ["--venvpath", "."]
2828

2929
- repo: https://github.com/rhysd/actionlint
3030
rev: v1.7.7

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
[![Python versions](https://img.shields.io/pypi/pyversions/configaroo.svg)](https://pypi.org/project/configaroo/)
55
[![License](https://img.shields.io/pypi/l/configaroo.svg)](https://github.com/gahjelle/configaroo/blob/main/LICENSE)
66
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
7-
[![Linted](https://github.com/gahjelle/configaroo/actions/workflows/lint.yml/badge.svg?branch=main)](https://github.com/gahjelle/configaroo/actions/workflows/lint.yml)
7+
[![Linted with Ruff](https://github.com/gahjelle/configaroo/actions/workflows/lint.yml/badge.svg?branch=main)](https://github.com/gahjelle/configaroo/actions/workflows/lint.yml)
88
[![Tested with Pytest](https://github.com/gahjelle/configaroo/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/gahjelle/configaroo/actions/workflows/test.yml)
9-
[![Type checked with mypy](https://img.shields.io/badge/type%20checked-mypy-green)](http://mypy-lang.org/)
9+
[![Type checked with pyright](https://microsoft.github.io/pyright/img/pyright_badge.svg)](https://microsoft.github.io/pyright/)
1010

1111
Configaroo is a light configuration package for Python that offers the following features:
1212

pyproject.toml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ changelog = "https://github.com/gahjelle/configaroo/releases"
3636

3737
[dependency-groups]
3838
build = ["build>=1.2.2.post1", "twine>=6.1.0"]
39-
ci = ["mypy>=1.17.1", "pytest>=8.4.1", "rich>=14.1.0", "ruff>=0.12.7", "tomli-w>=1.2.0"]
39+
ci = ["pytest>=8.4.1", "rich>=14.1.0", "ruff>=0.12.7", "tomli-w>=1.2.0"]
4040
dev = [
4141
{ include-group = "ci" },
4242
{ include-group = "test" },
4343
"bumpver>=2024.1130",
4444
"ipython>=8.36.0",
4545
"pre-commit>=4.2.0",
46+
"pyright>=1.1.404",
4647
]
4748
test = ["pytest>=8.4.1", "pytest-cov>=6.2.1", "tomli-w>=1.2.0"]
4849

@@ -74,9 +75,15 @@ ignore = [
7475
"tests/test_*.py" = ["PLR2004", "S101", "SLF001", "UP018"]
7576
"tests/*/test_*.py" = ["S101"]
7677

77-
[tool.mypy]
78-
python_version = "3.11"
79-
strict = true
78+
[tool.pyright]
79+
pythonVersion = "3.11"
80+
typeCheckingMode = "strict"
81+
verboseOutput = false
82+
include = ["src/", "tests/", "examples/"]
83+
venv = ".venv"
84+
85+
reportUnknownArgumentType = "none"
86+
reportUnknownMemberType = "none"
8087

8188
[tool.bumpver]
8289
current_version = "v0.5.0"

src/configaroo/configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def add_envs_from_model(
155155
self,
156156
model: type[BaseModel],
157157
prefix: str = "",
158-
types: type | UnionType = str | bool | int | float,
158+
types: type | UnionType = str | bool | int | float, # pyright: ignore[reportArgumentType]
159159
) -> Self:
160160
"""Add environment variables to configuration based on the given model.
161161

tests/test_configuration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ def test_find_pyproject_toml() -> None:
127127

128128
def test_find_foreign_caller() -> None:
129129
"""Test that a foreign caller (outside of configaroo) can be identified."""
130-
assert configuration._get_foreign_path() == Path(__file__)
130+
assert configuration._get_foreign_path() == Path(__file__) # pyright: ignore[reportPrivateUsage]
131131

132132

133133
def test_incomplete_formatter() -> None:
134134
"""Test that the incomplete formatter can handle fields that aren't replaced."""
135-
formatted = configuration._incomplete_format(
135+
formatted = configuration._incomplete_format( # pyright: ignore[reportPrivateUsage]
136136
"{number:5.1f} {non_existent} {string!r} {name}",
137137
{"number": 3.14, "string": "platypus", "name": "Geir Arne"},
138138
)

uv.lock

Lines changed: 18 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)