Skip to content

Commit dc1650c

Browse files
authored
refactor: Fix boolean traps in signatures (#287)
1 parent 2080fc0 commit dc1650c

File tree

30 files changed

+108
-84
lines changed

30 files changed

+108
-84
lines changed

docs/scripts/utils/markup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def symbol(self) -> str:
6262
return s
6363

6464
@classmethod
65-
def from_span(cls, span: MarkdownSpan, end: bool = False) -> MarkdownSymbol:
65+
def from_span(cls, span: MarkdownSpan, *, end: bool = False) -> MarkdownSymbol:
6666
return cls(
6767
position=span.end if end else span.start,
6868
italic=span.italic,

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ extend-select = [
171171
"C4", # flake8-comprehensions
172172
"B", # flake8-bugbear
173173
"UP", # pyupgrade
174+
"FBT002", # flake8-boolean-trap (Positional bool values with defaults)
174175
]
175176
ignore = [
176177
"E501", # Avoid enforcing line-length violations

tests/pyzabbix/test_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,12 @@ def test_client_logout(httpserver: HTTPServer, auth_type: AuthType, auth: str) -
240240

241241
# We only expect a logout request if we are using a sessionid and have an auth token
242242
if auth_type == "sessionid" and auth:
243-
add_zabbix_endpoint(httpserver, "user.logout", {}, True)
243+
add_zabbix_endpoint(
244+
httpserver,
245+
"user.logout",
246+
params={},
247+
response=True, # the value `True` as the response
248+
)
244249
zabbix_client = ZabbixAPI(server=httpserver.url_for("/api_jsonrpc.php"))
245250
zabbix_client.auth = auth
246251
if auth_type == "token":

tests/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
def add_zabbix_endpoint(
1414
httpserver: HTTPServer,
1515
method: str, # method is zabbix API method, not HTTP method
16+
*,
1617
params: dict[str, Any],
1718
response: Json,
1819
auth: Optional[str] = None,

zabbix_cli/_patches/typer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def patch__get_rich_console() -> None:
294294
)
295295
TYPER_THEME = Theme(styles)
296296

297-
def _get_rich_console(stderr: bool = False) -> Console:
297+
def _get_rich_console(stderr: bool = False) -> Console: # noqa: FBT002
298298
return Console(
299299
theme=TYPER_THEME,
300300
highlighter=highlighter,

zabbix_cli/auth.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def set_user_session(self, url: str, username: str, session_id: str) -> None:
126126
self.set_sessions(url, session)
127127

128128
@classmethod
129-
def load(cls, file: Path, allow_insecure: bool = False) -> SessionFile:
129+
def load(cls, file: Path, *, allow_insecure: bool = False) -> SessionFile:
130130
"""Load the contents of a session file."""
131131
if not file.exists():
132132
raise SessionFileNotFoundError("Session file does not exist: %s", file)
@@ -143,7 +143,9 @@ def load(cls, file: Path, allow_insecure: bool = False) -> SessionFile:
143143
except Exception as e:
144144
raise SessionFileError(f"Unable to load session file {file}: {e}") from e
145145

146-
def save(self, path: Optional[Path] = None, allow_insecure: bool = False) -> None:
146+
def save(
147+
self, path: Optional[Path] = None, *, allow_insecure: bool = False
148+
) -> None:
147149
path = path or self._path
148150
if not path:
149151
raise SessionFileError("Cannot save session file without a path.")
@@ -264,13 +266,13 @@ def login_with_any(self) -> tuple[ZabbixAPI, LoginInfo]:
264266
)
265267

266268
def _iter_all_credentials(
267-
self, prompt_password: bool = True
269+
self, *, prompt_password: bool = True
268270
) -> Generator[Credentials, None, None]:
269-
"""Generator that yields credentials from all possible sources.
271+
"""Generator of credentials from all possible sources.
270272
271273
Only yields non-empty credentials, but does not check if they are valid.
272274
273-
Finally yields a prompt for username and password if `prompt_password` is True.
275+
Finally yields a prompt for username and password if `prompt_password=True`.
274276
"""
275277
for func in [
276278
self._get_auth_token_env,
@@ -455,7 +457,7 @@ def _update_config(self, credentials: Credentials) -> None:
455457
):
456458
self.config.api.auth_token = SecretStr(credentials.auth_token)
457459

458-
def get_zabbix_url(self, prompt: bool = True) -> str:
460+
def get_zabbix_url(self, *, prompt: bool = True) -> str:
459461
"""Get the URL of the Zabbix server from env, config, then finally prompt for it.."""
460462
for source in [self._get_zabbix_url_env, self._get_zabbix_url_config]:
461463
url = source()
@@ -697,6 +699,7 @@ def write_auth_token_file(
697699
username: str,
698700
auth_token: str,
699701
file: Path = AUTH_TOKEN_FILE,
702+
*,
700703
allow_insecure: bool = False,
701704
) -> Path:
702705
"""Write a username/auth token pair to the auth token file."""

zabbix_cli/commands/results/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def config_path_str(self) -> str:
6161
)
6262

6363
@classmethod
64-
def from_debug_data(cls, state: State, with_auth: bool = False) -> DebugInfo:
64+
def from_debug_data(cls, state: State, *, with_auth: bool = False) -> DebugInfo:
6565
# So far we only use state, but we can expand this in the future
6666
from zabbix_cli.exceptions import ZabbixCLIError
6767

zabbix_cli/commands/results/proxy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class ShowProxiesResult(TableRenderable):
136136
show_hosts: bool = Field(default=False, exclude=True)
137137

138138
@classmethod
139-
def from_result(cls, proxy: Proxy, show_hosts: bool = False) -> Self:
139+
def from_result(cls, proxy: Proxy, *, show_hosts: bool = False) -> Self:
140140
return cls(proxy=proxy, show_hosts=show_hosts)
141141

142142
@property

zabbix_cli/commands/template.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ def link_template_to_host(
6666
from zabbix_cli.models import AggregateResult
6767

6868
templates = parse_templates_arg(
69-
app, template_names_or_ids, strict, select_hosts=True
69+
app, template_names_or_ids, strict=strict, select_hosts=True
7070
)
71-
hosts = parse_hosts_arg(app, hostnames_or_ids, strict)
71+
hosts = parse_hosts_arg(app, hostnames_or_ids, strict=strict)
7272
if not dryrun:
7373
with app.state.console.status("Linking templates..."):
7474
app.state.client.link_templates_to_hosts(templates, hosts)
@@ -280,9 +280,9 @@ def unlink_template_from_host(
280280
from zabbix_cli.models import AggregateResult
281281

282282
templates = parse_templates_arg(
283-
app, template_names_or_ids, strict, select_hosts=True
283+
app, template_names_or_ids, strict=strict, select_hosts=True
284284
)
285-
hosts = parse_hosts_arg(app, hostnames_or_ids, strict)
285+
hosts = parse_hosts_arg(app, hostnames_or_ids, strict=strict)
286286

287287
action = "Unlink and clear" if clear else "Unlink"
288288
if not dryrun:
@@ -362,8 +362,8 @@ def unlink_template_from_template(
362362
"""
363363
from zabbix_cli.commands.results.template import LinkTemplateResult
364364

365-
source_templates = parse_templates_arg(app, source, strict)
366-
dest_templates = parse_templates_arg(app, dest, strict)
365+
source_templates = parse_templates_arg(app, source, strict=strict)
366+
dest_templates = parse_templates_arg(app, dest, strict=strict)
367367
if not dryrun:
368368
with app.state.console.status("Unlinking templates..."):
369369
app.state.client.unlink_templates(

zabbix_cli/commands/templategroup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ def add_template_to_group(
6060

6161
groups: Union[list[HostGroup], list[TemplateGroup]]
6262
if app.state.client.version.release >= (6, 2, 0):
63-
groups = parse_templategroups_arg(app, group_names_or_ids, strict)
63+
groups = parse_templategroups_arg(app, group_names_or_ids, strict=strict)
6464
else:
65-
groups = parse_hostgroups_arg(app, group_names_or_ids, strict)
65+
groups = parse_hostgroups_arg(app, group_names_or_ids, strict=strict)
6666

67-
templates = parse_templates_arg(app, template_names_or_ids, strict)
67+
templates = parse_templates_arg(app, template_names_or_ids, strict=strict)
6868

6969
with app.state.console.status("Adding templates..."):
7070
app.state.client.link_templates_to_groups(templates, groups)

0 commit comments

Comments
 (0)