Skip to content

Commit c45d531

Browse files
Migrate to basedpyright
Lots of rules are currently disabled but we can re-enable them gradually in follow-up PRs
1 parent d30f920 commit c45d531

8 files changed

Lines changed: 67 additions & 55 deletions

File tree

.github/copilot-instructions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ The following checks run automatically via prek (pre-commit framework). All must
7777
9. **deptry** - Checks for missing/unused dependencies (`uv run deptry src`)
7878
10. **codespell** - Spell checker
7979
11. **import-linter** - Enforces architecture constraints (`uv run lint-imports`)
80-
12. **pyright** - Type checker (`uv run pyright`)
80+
12. **ty** - Type checker (`uv run ty`)
8181

8282
**To run all checks manually:**
8383
```bash
@@ -86,12 +86,12 @@ uv run prek run --all-files
8686

8787
**Individual validation commands:**
8888
```bash
89-
uv run ruff check --fix # Linter with autofixes
89+
uv run ruff check --fix # Linter with autofixes
9090
uv run ruff format # Formatter
9191
uv run deptry src # Dependency checker
9292
uv run codespell # Spell checker
9393
uv run lint-imports # Architecture constraints
94-
uv run pyright # Type checker
94+
uv run ty # Type checker
9595
```
9696

9797
## Architecture & Project Structure
@@ -270,7 +270,7 @@ These instructions have been validated by running actual commands and inspecting
270270
| Run all checks | `uv run prek run --all-files` |
271271
| Format code | `uv run ruff format` |
272272
| Lint code | `uv run ruff check --fix` |
273-
| Check types | `uv run pyright` |
273+
| Check types | `uv run ty` |
274274
| Check dependencies | `uv run deptry src` |
275275
| Check architecture | `uv run lint-imports` |
276276
| Serve docs | `uv run mkdocs serve` |

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
if: ${{ matrix.checks == null || matrix.checks == 'true' }}
5252
run: |
5353
uv run --frozen prek run --all-files
54-
uv run --frozen pyright
54+
uv run --frozen basedpyright
5555
5656
- name: Run pytest
5757
uses: pavelzw/pytest-action@510c5e90c360a185039bea56ce8b3e7e51a16507 # v2.2.0

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ If you're not interested in templating automations, then [configurator](https://
191191
Major features planned are:
192192

193193
- Support for automated GitHub Actions workflows ([#57](https://github.com/usethis-python/usethis-python/issues/57)), and
194-
- Support for a typechecker (likely Pyright, [#121](https://github.com/usethis-python/usethis-python/issues/121)).
194+
- Support for a typechecker (likely ty, [#838](https://github.com/usethis-python/usethis-python/issues/838)).
195195

196196
Other features are tracked in the [GitHub Issues](https://github.com/usethis-python/usethis-python/issues) page.
197197

pyproject.toml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ scripts.usethis = "usethis.__main__:app"
5454

5555
[dependency-groups]
5656
dev = [
57+
"basedpyright>=1.36.2",
5758
"datamodel-code-generator[http]>=0.35.0",
5859
"deptry>=0.23.0",
5960
"import-linter>=2.3",
6061
"jinja2>=3.1.6",
6162
"prek>=0.2.23",
6263
"pyinstrument>=5.1.1",
63-
"pyright[nodejs]>=1.1.399",
6464
"ruff>=0.14.3",
6565
"ty>=0.0.1a25",
6666
]
@@ -184,6 +184,38 @@ exclude_also = [
184184
]
185185
omit = [ "*/pytest-of-*/*", "*/_temp/*" ]
186186

187+
[tool.basedpyright]
188+
ignore = [ "src/usethis/_version.py" ]
189+
failOnWarnings = true
190+
reportAny = false
191+
reportArgumentType = false
192+
reportAssignmentType = false
193+
reportAttributeAccessIssue = false
194+
reportCallInDefaultInitializer = false
195+
reportExplicitAny = false
196+
reportImplicitOverride = false
197+
reportImplicitStringConcatenation = false
198+
reportImportCycles = false
199+
reportInvalidAbstractMethod = false
200+
reportMissingParameterType = false
201+
reportMissingTypeArgument = false
202+
reportMissingTypeStubs = false
203+
reportPrivateLocalImportUsage = false
204+
reportPrivateUsage = false
205+
reportUnannotatedClassAttribute = false
206+
reportUnknownArgumentType = false
207+
reportUnknownLambdaType = false
208+
reportUnknownMemberType = false
209+
reportUnknownParameterType = false
210+
reportUnknownVariableType = false
211+
reportUnnecessaryComparison = false
212+
reportUnnecessaryIsInstance = false
213+
reportUnnecessaryTypeIgnoreComment = false
214+
reportUnreachable = false
215+
reportUnusedFunction = false
216+
reportUnusedCallResult = false
217+
reportUnusedParameter = false
218+
187219
[tool.ty]
188220
environment.python-platform = "all"
189221
rules.type-assertion-failure = "ignore"

requirements.txt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ backrefs==5.8 \
2525
--hash=sha256:c67f6638a34a5b8730812f5101376f9d41dc38c43f1fdc35cb54700f6ed4465d \
2626
--hash=sha256:e3a63b073867dbefd0536425f43db618578528e3896fb77be7141328642a1585
2727
# via mkdocs-material
28+
basedpyright==1.36.2 \
29+
--hash=sha256:8dfd74fad77fcccc066ea0af5fd07e920b6f88cb1b403936aa78ab5aaef51526 \
30+
--hash=sha256:b596b1a6e6006c7dfd483efc1d602574f238321e28f70bc66e87255784b70630
2831
black==25.1.0 \
2932
--hash=sha256:030b9759066a4ee5e5aca28c3c77f9c64789cdd4de8ac1df642c40b708be6171 \
3033
--hash=sha256:055e59b198df7ac0b7efca5ad7ff2516bca343276c466be72eb04a3bcc1f82d7 \
@@ -521,10 +524,6 @@ mypy-extensions==1.0.0 \
521524
--hash=sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d \
522525
--hash=sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782
523526
# via black
524-
nodeenv==1.9.1 \
525-
--hash=sha256:6ec12890a2dab7946721edbfbcd91f3319c6ccc9aec47be7c7e6b7011ee6645f \
526-
--hash=sha256:ba11c9782d29c27c70ffbdda2d7415098754709be8a7056d79a737cd901155c9
527-
# via pyright
528527
nodejs-wheel-binaries==22.16.0 \
529528
--hash=sha256:2728972d336d436d39ee45988978d8b5d963509e06f063e80fe41b203ee80b28 \
530529
--hash=sha256:2fffb4bf1066fb5f660da20819d754f1b424bca1b234ba0f4fa901c52e3975fb \
@@ -535,7 +534,7 @@ nodejs-wheel-binaries==22.16.0 \
535534
--hash=sha256:986b715a96ed703f8ce0c15712f76fc42895cf09067d72b6ef29e8b334eccf64 \
536535
--hash=sha256:d695832f026df3a0cf9a089d222225939de9d1b67f8f0a353b79f015aabbe7e2 \
537536
--hash=sha256:dbfccbcd558d2f142ccf66d8c3a098022bf4436db9525b5b8d32169ce185d99e
538-
# via pyright
537+
# via basedpyright
539538
packaging==24.2 \
540539
--hash=sha256:09abb1bccd265c01f4a3aa3f7a7db064b36514d2cba19a2f694fe6150451a759 \
541540
--hash=sha256:c228a6dc5e932d346bc5739379109d49e8853dd8223571c7c5b55260edc0b97f
@@ -759,9 +758,6 @@ pymdown-extensions==10.19.1 \
759758
--hash=sha256:4969c691009a389fb1f9712dd8e7bd70dcc418d15a0faf70acb5117d022f7de8 \
760759
--hash=sha256:e8698a66055b1dc0dca2a7f2c9d0ea6f5faa7834a9c432e3535ab96c0c4e509b
761760
# via mkdocs-material
762-
pyright==1.1.403 \
763-
--hash=sha256:3ab69b9f41c67fb5bbb4d7a36243256f0d549ed3608678d381d5f51863921104 \
764-
--hash=sha256:c0eeca5aa76cbef3fcc271259bbd785753c7ad7bcac99a9162b4c4c7daed23b3
765761
pytest==8.3.5 \
766762
--hash=sha256:c69214aa47deac29fad6c2a4f590b9c4a9fdb16a403176fe154b79c0b4d4d820 \
767763
--hash=sha256:f4efe70cc14e511565ac476b57c279e12a855b11f48f212af1080ef2263d3845
@@ -1023,7 +1019,6 @@ typing-extensions==4.15.0 \
10231019
# import-linter
10241020
# pydantic
10251021
# pydantic-core
1026-
# pyright
10271022
# rich
10281023
# typer
10291024
# typing-inspection

tests/usethis/_integrations/ci/bitbucket/test_yaml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_change_image(self, tmp_path: Path):
5555
with change_cwd(tmp_path), BitbucketPipelinesYAMLManager() as mgr:
5656
doc = mgr.get()
5757
mgr.model_validate()
58-
assert isinstance(doc.content, dict) # Help pyright
58+
assert isinstance(doc.content, dict) # Help type checker
5959
doc.content["image"] = "atlassian/default-image:2"
6060
mgr.commit(doc)
6161

@@ -84,7 +84,7 @@ def test_change_default(self, tmp_path: Path):
8484
with change_cwd(tmp_path), BitbucketPipelinesYAMLManager() as mgr:
8585
doc = mgr.get()
8686
mgr.model_validate()
87-
# Help pyright with assertions
87+
# Help type checker with assertions
8888
assert isinstance(doc.content, dict)
8989
assert isinstance(doc.content["pipelines"], dict)
9090
assert isinstance(doc.content["pipelines"]["default"], list)

tests/usethis/_integrations/file/yaml/test_update.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_no_change(self, tmp_path: Path):
1919

2020
# Act
2121
with edit_yaml(path) as yaml_document:
22-
assert isinstance(yaml_document.content, CommentedMap) # Help pyright
22+
assert isinstance(yaml_document.content, CommentedMap)
2323
update_ruamel_yaml_map(
2424
yaml_document.content,
2525
{"hello": "world"},
@@ -43,7 +43,7 @@ def test_map(self, tmp_path: Path):
4343

4444
# Act
4545
with edit_yaml(path) as yaml_document:
46-
assert isinstance(yaml_document.content, CommentedMap) # Help pyright
46+
assert isinstance(yaml_document.content, CommentedMap)
4747
update_ruamel_yaml_map(
4848
yaml_document.content,
4949
{"hello": "universe"},
@@ -70,7 +70,7 @@ def test_list(self, tmp_path: Path):
7070

7171
# Act
7272
with edit_yaml(path) as yaml_document:
73-
assert isinstance(yaml_document.content, CommentedMap) # Help pyright
73+
assert isinstance(yaml_document.content, CommentedMap)
7474
update_ruamel_yaml_map(
7575
yaml_document.content,
7676
{"key": [1, 2, 4]},
@@ -98,7 +98,7 @@ def test_remove_key(self, tmp_path: Path):
9898

9999
# Act
100100
with edit_yaml(path) as yaml_document:
101-
assert isinstance(yaml_document.content, CommentedMap) # Help pyright
101+
assert isinstance(yaml_document.content, CommentedMap)
102102
update_ruamel_yaml_map(
103103
yaml_document.content,
104104
{"key": "new value"},
@@ -124,7 +124,7 @@ def test_nested_map(self, tmp_path: Path):
124124

125125
# Act
126126
with edit_yaml(path) as yaml_document:
127-
assert isinstance(yaml_document.content, CommentedMap) # Help pyright
127+
assert isinstance(yaml_document.content, CommentedMap)
128128
update_ruamel_yaml_map(
129129
yaml_document.content,
130130
{"key": {"hello": "universe"}, "banana": "yummy"},
@@ -159,8 +159,8 @@ def test_reuse_ref(self, tmp_path: Path):
159159

160160
# Act
161161
with edit_yaml(path) as yaml_document:
162-
assert isinstance(yaml_document.content, CommentedMap) # Help pyright
163-
assert isinstance(another_yaml_doc.content, CommentedMap) # Help pyright
162+
assert isinstance(yaml_document.content, CommentedMap)
163+
assert isinstance(another_yaml_doc.content, CommentedMap)
164164
update_ruamel_yaml_map(
165165
yaml_document.content,
166166
{"key": [1, another_yaml_doc.content, another_yaml_doc.content.copy()]},
@@ -382,7 +382,7 @@ def test_ruamel_yaml_file(self, tmp_path: Path):
382382
""")
383383

384384
with edit_yaml(path) as yaml_document:
385-
assert isinstance(yaml_document.content, CommentedSeq) # Help pyright
385+
assert isinstance(yaml_document.content, CommentedSeq)
386386
# Act
387387
lcs_list_update(yaml_document.content, [1, 2, 4])
388388

uv.lock

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

0 commit comments

Comments
 (0)