Skip to content

Commit 0fdcc79

Browse files
authored
Merge pull request #760 from seapagan/update-ruff-and-fix
Breaking - Refactor `UserManager.set_ban_status` signature.
2 parents e291ede + 81f2d85 commit 0fdcc79

14 files changed

Lines changed: 104 additions & 85 deletions

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repos:
1818
# files: ^renovate\.json$
1919

2020
- repo: https://github.com/astral-sh/ruff-pre-commit
21-
rev: v0.11.11
21+
rev: v0.12.2
2222
hooks:
2323
- id: ruff
2424
args: ["--output-format=concise"]
@@ -27,7 +27,7 @@ repos:
2727
name: "format with ruff"
2828

2929
- repo: https://github.com/pre-commit/mirrors-mypy
30-
rev: "v1.15.0" # Use the sha / tag you want to point at
30+
rev: "v1.16.1" # Use the sha / tag you want to point at
3131
hooks:
3232
- id: mypy
3333
name: "run mypy"
@@ -37,7 +37,7 @@ repos:
3737

3838
- repo: https://github.com/astral-sh/uv-pre-commit
3939
# uv version.
40-
rev: 0.7.8
40+
rev: 0.7.19
4141
hooks:
4242
# Update the uv lockfile
4343
- id: uv-lock

app/api_admin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def cli_header() -> None:
2727

2828
@app.callback(invoke_without_command=True)
2929
def main(
30+
*,
3031
version: Optional[bool] = typer.Option(
3132
False,
3233
"--version",

app/commands/db.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
@app.command()
3333
def init(
34+
*,
3435
force: Optional[bool] = typer.Option(
3536
False,
3637
"--force",
@@ -58,6 +59,7 @@ def init(
5859

5960
@app.command()
6061
def drop(
62+
*,
6163
force: Optional[bool] = typer.Option(
6264
False,
6365
"--force",
@@ -307,6 +309,7 @@ def seed(
307309
help="Path to the CSV file containing user data",
308310
),
309311
] = Path("users.seed"),
312+
*,
310313
force: Optional[bool] = typer.Option(
311314
False,
312315
"--force",

app/commands/dev.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def serve(
2020
"-h",
2121
help="Define the interface to run the server on.",
2222
),
23+
*,
2324
reload: Optional[bool] = typer.Option(
2425
True,
2526
help="Enable auto-reload on code changes",

app/commands/user.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def create(
9292
show_default=False,
9393
hide_input=True,
9494
),
95+
*,
9596
admin: Optional[bool] = typer.Option(
9697
False,
9798
"--admin",
@@ -235,6 +236,7 @@ def ban(
235236
help="The user's id",
236237
show_default=False,
237238
),
239+
*,
238240
unban: Optional[bool] = typer.Option(
239241
False,
240242
"--unban",
@@ -245,7 +247,7 @@ def ban(
245247
) -> None:
246248
"""Ban or Unban a user by id."""
247249

248-
async def _ban_user(user_id: int, unban: Optional[bool]) -> User | None:
250+
async def _ban_user(user_id: int, *, unban: Optional[bool]) -> User | None:
249251
"""Async function to ban or unban a user."""
250252
try:
251253
async with async_session() as session:
@@ -259,7 +261,7 @@ async def _ban_user(user_id: int, unban: Optional[bool]) -> User | None:
259261
else:
260262
return user
261263

262-
user = aiorun(_ban_user(user_id, unban))
264+
user = aiorun(_ban_user(user_id, unban=unban))
263265
if user:
264266
rprint(
265267
f"\n[green]-> User [bold]{user_id}[/bold] "
@@ -280,6 +282,7 @@ def admin(
280282
help="The user's id",
281283
show_default=False,
282284
),
285+
*,
283286
remove: Optional[bool] = typer.Option(
284287
False,
285288
"--remove",
@@ -291,7 +294,7 @@ def admin(
291294
"""Make a user an admin or remove admin status."""
292295

293296
async def _toggle_admin(
294-
user_id: int, remove: Optional[bool]
297+
user_id: int, *, remove: Optional[bool]
295298
) -> User | None:
296299
"""Async function to toggle admin status for a user."""
297300
try:
@@ -306,7 +309,7 @@ async def _toggle_admin(
306309
else:
307310
return user
308311

309-
user = aiorun(_toggle_admin(user_id, remove))
312+
user = aiorun(_toggle_admin(user_id, remove=remove))
310313
if user:
311314
status = "removed from" if remove else "granted to"
312315
rprint(

app/managers/email.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
class EmailManager:
2020
"""Class to manage all Email operations."""
2121

22-
def __init__(self, suppress_send: Optional[bool] = False) -> None:
22+
def __init__(self, *, suppress_send: Optional[bool] = False) -> None:
2323
"""Initialize the EmailManager.
2424
2525
Define the configuration instance.

app/managers/user.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,11 @@ async def change_password(
264264

265265
@staticmethod
266266
async def set_ban_status(
267-
user_id: int, state: Optional[bool], my_id: int, session: AsyncSession
267+
user_id: int,
268+
my_id: int,
269+
session: AsyncSession,
270+
*,
271+
banned: Optional[bool],
268272
) -> None:
269273
"""Ban or un-ban the specified user based on supplied status."""
270274
if my_id == user_id:
@@ -276,13 +280,13 @@ async def set_ban_status(
276280
raise HTTPException(
277281
status.HTTP_404_NOT_FOUND, ErrorMessages.USER_INVALID
278282
)
279-
if bool(check_user.banned) == state:
283+
if bool(check_user.banned) == banned:
280284
raise HTTPException(
281285
status.HTTP_400_BAD_REQUEST,
282286
ErrorMessages.ALREADY_BANNED_OR_UNBANNED,
283287
)
284288
await session.execute(
285-
update(User).where(User.id == user_id).values(banned=state)
289+
update(User).where(User.id == user_id).values(banned=banned)
286290
)
287291

288292
@staticmethod

app/resources/user.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ async def ban_user(
101101
102102
Admins only. The Admin cannot ban their own ID!
103103
"""
104-
await UserManager.set_ban_status(user_id, True, request.state.user.id, db)
104+
await UserManager.set_ban_status(
105+
user_id, request.state.user.id, db, banned=True
106+
)
105107

106108

107109
@router.post(
@@ -118,7 +120,9 @@ async def unban_user(
118120
119121
Admins only.
120122
"""
121-
await UserManager.set_ban_status(user_id, False, request.state.user.id, db)
123+
await UserManager.set_ban_status(
124+
user_id, request.state.user.id, db, banned=False
125+
)
122126

123127

124128
@router.put(

requirements-dev.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ mkdocstrings==0.28.1
224224
mkdocstrings-python==1.16.0
225225
# via mkdocstrings
226226
mock==5.1.0
227-
mypy==1.15.0
227+
mypy==1.16.1
228228
mypy-extensions==1.0.0
229229
# via mypy
230230
nodeenv==1.9.1
@@ -241,7 +241,9 @@ paginate==0.5.7
241241
pastel==0.2.1
242242
# via poethepoet
243243
pathspec==0.12.1
244-
# via mkdocs
244+
# via
245+
# mkdocs
246+
# mypy
245247
platformdirs==4.3.6
246248
# via
247249
# mkdocs-get-deps
@@ -354,7 +356,7 @@ rtoml==0.12.0
354356
# api-template
355357
# github-changelog-md
356358
# simple-toml-settings
357-
ruff==0.11.11
359+
ruff==0.12.2
358360
shellingham==1.5.4
359361
# via typer
360362
simple-toml-settings==0.9.0

tests/cli/test_cli_custom_command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,11 @@ def reimport_custom_module() -> None:
378378
the 'pytest.raises' context manager and upsetting 'ruff' linter.
379379
"""
380380
if "app.commands.custom" in sys.modules:
381-
import importlib
381+
import importlib # noqa: PLC0415
382382

383383
importlib.reload(sys.modules["app.commands.custom"])
384384
else:
385-
import app.commands.custom # noqa: F401
385+
import app.commands.custom # noqa: F401, PLC0415
386386

387387
# Store and patch the import mechanism
388388
original_import = __import__

0 commit comments

Comments
 (0)