Skip to content

Commit f9f460c

Browse files
committed
Enable ruff ANN ruleset to warn about missing type annotations for arguments and return values
However, globally disabled rule ANN401 which disallows use of `typing.Any` because that is just too strict for now.
1 parent eba5b80 commit f9f460c

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

cmd2/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def __init__(
150150
"""
151151
if val_type is bool:
152152

153-
def get_bool_choices(_) -> list[str]: # type: ignore[no-untyped-def]
153+
def get_bool_choices(_: str) -> list[str]:
154154
"""Used to tab complete lowercase boolean values."""
155155
return ['true', 'false']
156156

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ select = [
158158
# https://docs.astral.sh/ruff/rules
159159
"A", # flake8-builtins (variables or arguments shadowing built-ins)
160160
# "AIR", # Airflow specific warnings
161-
# "ANN", # flake8-annotations (missing type annotations for arguments or return types)
161+
"ANN", # flake8-annotations (missing type annotations for arguments or return types)
162162
# "ARG", # flake8-unused-arguments (functions or methods with arguments that are never used)
163163
"ASYNC", # flake8-async (async await bugs)
164164
# "B", # flake8-bugbear (various likely bugs and design issues)
@@ -222,6 +222,7 @@ select = [
222222
]
223223
ignore = [
224224
# `uv run ruff rule E501` for a description of that rule
225+
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed (would be good to enable this later)
225226
"COM812", # Conflicts with ruff format (see https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules)
226227
"COM819", # Conflicts with ruff format
227228
"D206", # Conflicts with ruff format

tasks.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
import re
1313
import shutil
1414
import sys
15+
from typing import Union
1516

1617
import invoke
18+
from invoke.context import Context
1719

1820
from plugins import (
1921
tasks as plugin_tasks,
@@ -24,7 +26,7 @@
2426

2527

2628
# shared function
27-
def rmrf(items, verbose=True) -> None:
29+
def rmrf(items: Union[str, list[str], set[str]], verbose: bool = True) -> None:
2830
"""Silently remove a list of directories or files."""
2931
if isinstance(items, str):
3032
items = [items]
@@ -51,7 +53,7 @@ def rmrf(items, verbose=True) -> None:
5153

5254

5355
@invoke.task()
54-
def pytest(context, junit=False, pty=True, base=False, isolated=False) -> None:
56+
def pytest(context: Context, junit: bool = False, pty: bool = True, base: bool = False, isolated: bool = False) -> None:
5557
"""Run tests and code coverage using pytest."""
5658
with context.cd(TASK_ROOT_STR):
5759
command_str = 'pytest '
@@ -79,7 +81,7 @@ def pytest(context, junit=False, pty=True, base=False, isolated=False) -> None:
7981

8082

8183
@invoke.task(post=[plugin_tasks.pytest_clean])
82-
def pytest_clean(context) -> None:
84+
def pytest_clean(context: Context) -> None:
8385
"""Remove pytest cache and code coverage files and directories."""
8486
# pylint: disable=unused-argument
8587
with context.cd(str(TASK_ROOT / 'tests')):
@@ -92,7 +94,7 @@ def pytest_clean(context) -> None:
9294

9395

9496
@invoke.task()
95-
def mypy(context) -> None:
97+
def mypy(context: Context) -> None:
9698
"""Run mypy optional static type checker."""
9799
with context.cd(TASK_ROOT_STR):
98100
context.run("mypy .")
@@ -102,7 +104,7 @@ def mypy(context) -> None:
102104

103105

104106
@invoke.task()
105-
def mypy_clean(context) -> None:
107+
def mypy_clean(context: Context) -> None:
106108
"""Remove mypy cache directory."""
107109
# pylint: disable=unused-argument
108110
with context.cd(TASK_ROOT_STR):
@@ -123,7 +125,7 @@ def mypy_clean(context) -> None:
123125

124126

125127
@invoke.task()
126-
def docs(context, builder='html') -> None:
128+
def docs(context: Context, builder: str = 'html') -> None:
127129
"""Build documentation using MkDocs."""
128130
with context.cd(TASK_ROOT_STR):
129131
context.run('mkdocs build', pty=True)
@@ -133,7 +135,7 @@ def docs(context, builder='html') -> None:
133135

134136

135137
@invoke.task
136-
def docs_clean(context) -> None:
138+
def docs_clean(context: Context) -> None:
137139
"""Remove rendered documentation."""
138140
# pylint: disable=unused-argument
139141
with context.cd(TASK_ROOT_STR):
@@ -144,7 +146,7 @@ def docs_clean(context) -> None:
144146

145147

146148
@invoke.task
147-
def livehtml(context) -> None:
149+
def livehtml(context: Context) -> None:
148150
"""Launch webserver on http://localhost:8000 with rendered documentation."""
149151
with context.cd(TASK_ROOT_STR):
150152
context.run('mkdocs serve', pty=True)
@@ -163,7 +165,7 @@ def livehtml(context) -> None:
163165

164166

165167
@invoke.task(post=[plugin_tasks.build_clean])
166-
def build_clean(context) -> None:
168+
def build_clean(context: Context) -> None:
167169
"""Remove the build directory."""
168170
# pylint: disable=unused-argument
169171
with context.cd(TASK_ROOT_STR):
@@ -174,7 +176,7 @@ def build_clean(context) -> None:
174176

175177

176178
@invoke.task(post=[plugin_tasks.dist_clean])
177-
def dist_clean(context) -> None:
179+
def dist_clean(context: Context) -> None:
178180
"""Remove the dist directory."""
179181
# pylint: disable=unused-argument
180182
with context.cd(TASK_ROOT_STR):
@@ -185,7 +187,7 @@ def dist_clean(context) -> None:
185187

186188

187189
@invoke.task()
188-
def eggs_clean(context) -> None:
190+
def eggs_clean(context: Context) -> None:
189191
"""Remove egg directories."""
190192
# pylint: disable=unused-argument
191193
with context.cd(TASK_ROOT_STR):
@@ -203,7 +205,7 @@ def eggs_clean(context) -> None:
203205

204206

205207
@invoke.task()
206-
def pycache_clean(context) -> None:
208+
def pycache_clean(context: Context) -> None:
207209
"""Remove __pycache__ directories."""
208210
# pylint: disable=unused-argument
209211
with context.cd(TASK_ROOT_STR):
@@ -220,7 +222,7 @@ def pycache_clean(context) -> None:
220222

221223
# ruff fast linter
222224
@invoke.task()
223-
def lint(context) -> None:
225+
def lint(context: Context) -> None:
224226
"""Run ruff fast linter."""
225227
with context.cd(TASK_ROOT_STR):
226228
context.run("ruff check")
@@ -231,7 +233,7 @@ def lint(context) -> None:
231233

232234
# ruff fast formatter
233235
@invoke.task()
234-
def format(context) -> None: # noqa: A001
236+
def format(context: Context) -> None: # noqa: A001
235237
"""Run ruff format --check."""
236238
with context.cd(TASK_ROOT_STR):
237239
context.run("ruff format --check")
@@ -241,7 +243,7 @@ def format(context) -> None: # noqa: A001
241243

242244

243245
@invoke.task()
244-
def ruff_clean(context) -> None:
246+
def ruff_clean(context: Context) -> None:
245247
"""Remove .ruff_cache directory."""
246248
with context.cd(TASK_ROOT_STR):
247249
context.run("ruff clean")
@@ -256,7 +258,7 @@ def ruff_clean(context) -> None:
256258

257259

258260
@invoke.task(pre=clean_tasks, default=True)
259-
def clean_all(_) -> None:
261+
def clean_all(_: Context) -> None:
260262
"""Run all clean tasks."""
261263
# pylint: disable=unused-argument
262264

@@ -265,7 +267,7 @@ def clean_all(_) -> None:
265267

266268

267269
@invoke.task
268-
def tag(context, name, message='') -> None:
270+
def tag(context: Context, name: str, message: str = '') -> None:
269271
"""Add a Git tag and push it to origin."""
270272
# If a tag was provided on the command-line, then add a Git tag and push it to origin
271273
if name:
@@ -277,7 +279,7 @@ def tag(context, name, message='') -> None:
277279

278280

279281
@invoke.task()
280-
def validatetag(context) -> None:
282+
def validatetag(context: Context) -> None:
281283
"""Check to make sure that a tag exists for the current HEAD and it looks like a valid version number."""
282284
# Validate that a Git tag exists for the current commit HEAD
283285
result = context.run("git describe --exact-match --tags $(git log -n1 --pretty='%h')")
@@ -297,7 +299,7 @@ def validatetag(context) -> None:
297299

298300

299301
@invoke.task(pre=[clean_all], post=[plugin_tasks.sdist])
300-
def sdist(context) -> None:
302+
def sdist(context: Context) -> None:
301303
"""Create a source distribution."""
302304
with context.cd(TASK_ROOT_STR):
303305
context.run('python -m build --sdist')
@@ -307,7 +309,7 @@ def sdist(context) -> None:
307309

308310

309311
@invoke.task(pre=[clean_all], post=[plugin_tasks.wheel])
310-
def wheel(context) -> None:
312+
def wheel(context: Context) -> None:
311313
"""Build a wheel distribution."""
312314
with context.cd(TASK_ROOT_STR):
313315
context.run('python -m build --wheel')
@@ -317,7 +319,7 @@ def wheel(context) -> None:
317319

318320

319321
@invoke.task(pre=[validatetag, sdist, wheel])
320-
def pypi(context) -> None:
322+
def pypi(context: Context) -> None:
321323
"""Build and upload a distribution to pypi."""
322324
with context.cd(TASK_ROOT_STR):
323325
context.run('twine upload dist/*')
@@ -327,7 +329,7 @@ def pypi(context) -> None:
327329

328330

329331
@invoke.task(pre=[validatetag, sdist, wheel])
330-
def pypi_test(context) -> None:
332+
def pypi_test(context: Context) -> None:
331333
"""Build and upload a distribution to https://test.pypi.org."""
332334
with context.cd(TASK_ROOT_STR):
333335
context.run('twine upload --repository testpypi dist/*')

0 commit comments

Comments
 (0)