Skip to content

Commit cf5950e

Browse files
Merge branch 'main' into 1322-enable-reportimplicitoverride-in-basedpyright
2 parents 0f57dd7 + d2dbac5 commit cf5950e

17 files changed

Lines changed: 35 additions & 59 deletions

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Tool implementations are defined in classes in the `usethis._tool.impl` module.
142142
- Start by implementing its `name` property method, then work through the other methods. Most method have default implementations, but even in those cases you will need to consider them individually and determine an appropriate implementation. For example, methods which specify the tool's dependencies default to empty dependencies, but you shouldn't rely on this.
143143
- Mark all methods in your `ToolSpec` subclass with the `@typing.final` decorator. This prevents the methods from being accidentally overridden in the `Tool` subclass.
144144
- Then, define a subclass of the `ToolSpec` subclass you just created, which also subclasses `usethis._tool.base.Tool`, e.g. for a tool named Xyz, define a class `XyzTool(XyzToolSpec, Tool)`. The only method this usually requires a non-default implementation for is `config_spec` to specify which configuration sections should be set up for the tool (and which sections the tool manages). However, you may find it helpful to provide custom implementations for other methods as well, e.g. `print_how_to_use`.
145-
- Mark all methods in your `Tool` subclass with `@final` as well, to prevent further subclassing from overriding them.
145+
- Mark your `Tool` subclass with `@final` as well, to prevent further subclassing.
146146

147147
#### Register your `Tool` subclass
148148

pyproject.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ reportImplicitStringConcatenation = false
215215
reportMissingParameterType = false
216216
reportMissingTypeArgument = false
217217
reportPrivateUsage = false
218-
reportUnannotatedClassAttribute = false
219218
reportUnknownArgumentType = false
220219
reportUnknownMemberType = false
221220
reportUnknownVariableType = false
@@ -224,11 +223,22 @@ reportUnusedCallResult = false
224223

225224
[[tool.basedpyright.executionEnvironments]]
226225
root = "tests"
226+
reportUnannotatedClassAttribute = false
227227
reportUnknownLambdaType = false
228228
reportUnknownParameterType = false
229229
reportUnreachable = false
230230
reportUnusedFunction = false
231231
reportUnusedParameter = false
232232

233+
[[tool.basedpyright.executionEnvironments]]
234+
# Particularly interested in avoiding the auto-generated schema script
235+
root = "src/usethis/_integrations/ci/bitbucket"
236+
reportUnannotatedClassAttribute = false
237+
238+
[[tool.basedpyright.executionEnvironments]]
239+
# Particularly interested in avoiding the auto-generated schema script
240+
root = "src/usethis/_integrations/pre_commit"
241+
reportUnannotatedClassAttribute = false
242+
233243
[tool.sync-with-uv.repo-to-package]
234244
"https://github.com/astral-sh/uv-pre-commit" = "uv"

src/usethis/_core/docstyle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ def use_docstyle(style: DocStyleEnum) -> None:
1515

1616
RuffTool().set_docstyle(style.value)
1717

18-
if not RuffTool()._are_pydocstyle_rules_selected():
18+
if not RuffTool().are_pydocstyle_rules_selected():
1919
RuffTool().select_rules(["D2", "D3", "D4"])

src/usethis/_io.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class UsethisFileManager(Generic[DocumentT], metaclass=ABCMeta):
4040
# https://github.com/python/mypy/issues/5144
4141
# The Any in this expression should be identified with DocumentT
4242
_content_by_path: ClassVar[dict[Path, Any | None]] = {}
43+
path: Path
4344

4445
@property
4546
@abstractmethod

src/usethis/_tool/impl/base/codespell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from usethis._tool.impl.spec.codespell import CodespellToolSpec
1010

1111

12+
@final
1213
class CodespellTool(CodespellToolSpec, Tool):
1314
@override
14-
@final
1515
def print_how_to_use(self) -> None:
1616
how_print(f"Run '{self.how_to_use_cmd()}' to run the {self.name} spellchecker.")

src/usethis/_tool/impl/base/coverage_py.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@
1515
from usethis._types.deps import Dependency
1616

1717

18+
@final
1819
class CoveragePyTool(CoveragePyToolSpec, Tool):
1920
@override
20-
@final
2121
def test_deps(self, *, unconditional: bool = False) -> list[Dependency]:
2222
deps = [Dependency(name="coverage", extras=frozenset({"toml"}))]
2323
if unconditional or is_likely_used(PytestToolSpec()):
2424
deps += [Dependency(name="pytest-cov")]
2525
return deps
2626

2727
@override
28-
@final
2928
def print_how_to_use(self) -> None:
3029
backend = get_backend()
3130

src/usethis/_tool/impl/base/deptry.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@
1717
from usethis._io import KeyValueFileManager
1818

1919

20+
@final
2021
class DeptryTool(DeptryToolSpec, Tool):
2122
@override
22-
@final
2323
def select_rules(self, rules: Sequence[Rule]) -> bool:
2424
"""Does nothing for deptry - all rules are automatically enabled by default."""
2525
if rules:
2626
info_print(f"All {self.name} rules are always implicitly selected.")
2727
return False
2828

2929
@override
30-
@final
3130
def selected_rules(self) -> list[Rule]:
3231
"""No notion of selection for deptry.
3332
@@ -37,13 +36,11 @@ def selected_rules(self) -> list[Rule]:
3736
return []
3837

3938
@override
40-
@final
4139
def deselect_rules(self, rules: Sequence[Rule]) -> bool:
4240
"""Does nothing for deptry - all rules are automatically enabled by default."""
4341
return False
4442

4543
@override
46-
@final
4744
def ignored_rules(self) -> list[Rule]:
4845
(file_manager,) = self.get_active_config_file_managers()
4946
keys = self._get_ignore_keys(file_manager)
@@ -55,7 +52,6 @@ def ignored_rules(self) -> list[Rule]:
5552
return rules
5653

5754
@override
58-
@final
5955
def _get_ignore_keys(self, file_manager: KeyValueFileManager[object]) -> list[str]:
6056
"""Get the keys for the ignored rules in the given file manager."""
6157
if isinstance(file_manager, PyprojectTOMLManager):

src/usethis/_tool/impl/base/import_linter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
from usethis._tool.rule import Rule
1515

1616

17+
@final
1718
class ImportLinterTool(ImportLinterToolSpec, Tool):
1819
@override
19-
@final
2020
def is_used(self) -> bool:
2121
"""Check if the Import Linter tool is used in the project."""
2222
# We suppress the warning about assumptions regarding the package name.
@@ -25,7 +25,6 @@ def is_used(self) -> bool:
2525
return super().is_used()
2626

2727
@override
28-
@final
2928
def print_how_to_use(self) -> None:
3029
if not _is_inp_rule_selected():
3130
# If Ruff is used, we enable the INP rules instead.

src/usethis/_tool/impl/base/mkdocs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
from usethis._types.backend import BackendEnum
1313

1414

15+
@final
1516
class MkDocsTool(MkDocsToolSpec, Tool):
1617
@override
17-
@final
1818
def print_how_to_use(self) -> None:
1919
backend = get_backend()
2020
if backend is BackendEnum.uv and is_uv_used():

src/usethis/_tool/impl/base/pre_commit.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,17 @@
1919
from usethis._python.version import PythonVersion
2020

2121

22+
@final
2223
class PreCommitTool(PreCommitToolSpec, Tool):
2324
@override
24-
@final
2525
def is_used(self) -> bool:
2626
return is_pre_commit_used()
2727

2828
@override
29-
@final
3029
def print_how_to_use(self) -> None:
3130
how_print(f"Run '{self.how_to_use_cmd()}' to run the hooks manually.")
3231

3332
@override
34-
@final
3533
def get_bitbucket_steps(
3634
self,
3735
*,
@@ -70,7 +68,6 @@ def get_bitbucket_steps(
7068
assert_never(backend)
7169

7270
@override
73-
@final
7471
def update_bitbucket_steps(self, *, matrix_python: bool = True) -> None:
7572
"""Add Bitbucket steps associated with pre-commit, and remove outdated ones.
7673
@@ -83,11 +80,9 @@ def update_bitbucket_steps(self, *, matrix_python: bool = True) -> None:
8380
self._unconditional_update_bitbucket_steps(matrix_python=matrix_python)
8481

8582
@override
86-
@final
8783
def migrate_config_to_pre_commit(self) -> None:
8884
pass
8985

9086
@override
91-
@final
9287
def migrate_config_from_pre_commit(self) -> None:
9388
pass

0 commit comments

Comments
 (0)