Skip to content

Commit 7f88cff

Browse files
tbitcsoz-agent
andcommitted
fix: suppress DeprecationWarning on ctx.protected_args access (Click 9 compat)
Accessing ctx.protected_args emits the warning even when guarded by an if-check. Wrap the access in warnings.catch_warnings() to silence it; fall back to ctx.args[0] for Click 9.0 where the subcommand moves there. Co-Authored-By: Oz <oz-agent@warp.dev>
1 parent 38d2edc commit 7f88cff

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/specsmith/cli.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,14 @@ def invoke(self, ctx: click.Context) -> object:
4949
import os
5050

5151
# Skip if explicitly disabled or if this is a meta-command
52-
# ctx.protected_args is deprecated in Click 9.0; args will carry all tokens
53-
all_args = (ctx.protected_args or []) + (ctx.args or [])
54-
subcommand = all_args[0] if all_args else ""
52+
# ctx.protected_args is deprecated in Click 9.0; suppress the warning
53+
# on access (it still works in 8.x). In 9.0 the subcommand moves to args.
54+
import warnings
55+
56+
with warnings.catch_warnings():
57+
warnings.simplefilter("ignore", DeprecationWarning)
58+
protected = list(ctx.protected_args) # [subcommand] in 8.x, [] in 9.0
59+
subcommand = protected[0] if protected else (ctx.args[0] if ctx.args else "")
5560
skip = (
5661
os.environ.get("SPECSMITH_NO_AUTO_UPDATE", "").strip() in ("1", "true", "yes")
5762
or subcommand in self._SKIP_COMMANDS

0 commit comments

Comments
 (0)