SKY-L029 · Logic and resilience
Unclear boolean argument
A function takes a True/False switch as an ordinary positional parameter, so callers can write send_invoice(invoice, True). At the call site nobody can tell what True means without opening the function. This is often called a boolean trap.
- Languages
- Python
- Quality gate
- counted toward the gate limits (full and diff scans). Only when listed. This is advice outside the default set: the report keeps it in JSON but does not list it, and the gate does not count it, unless you pass
--all-adviceor select the rule (--select SKY-L029). A finding based only on the signature, with no call that passes a bareTrueorFalse, is hidden for the same reason. - Finding type
- advice
Why it matters
Readers guess, and reviewers miss swapped arguments: send(invoice, True, False) and send(invoice, False, True) look equally plausible. A switch added later in the wrong position still type-checks.
What Skylos flags
"""Send monthly invoices.""" from billing.mail import send_mail def send_invoice(invoice, include_pdf: bool = False): attachments = [invoice.render_pdf()] if include_pdf else [] send_mail(invoice.customer.email, invoice.summary(), attachments) def close_month(invoices): for invoice in invoices: send_invoice(invoice, True)What Skylos leaves alone
"""Send monthly invoices.""" def sort_invoices(invoices, reverse=False): return sorted(invoices, key=lambda invoice: invoice.due_date, reverse=reverse) def newest_first(invoices): return sort_invoices(invoices, True)Why Skylos leaves it alone
reverse is one of a few switch names that are familiar from Python itself (sorted(..., reverse=True)), along with inplace, recursive, verbose, debug, force, dry_run and strict. Skylos accepts those on public functions.
How Skylos decides
- Runs with
--qualityon Python functions and methods. Test files, examples and build scripts are skipped, and so are dunder methods,self,clsand a property setter's value. - A parameter is a candidate when it can be passed by position (it is not after
*) and it is annotatedbool(the builtin) or has aTrueorFalsedefault. - Skips functions decorated
@overrideor@overload, methods that override a base class in the same file, and functions passed around as values (callbacks must keep their signature). - For a public function, reports every candidate except the familiar names
inplace,reverse,recursive,verbose,debug,force,dry_runandstrict. A private (_name) or nested function is reported only when a call in the same file passes a bareTrueorFalsein that position. - Reports LOW on the parameter's line. When such calls exist, the message lists them.
How to fix it
Make the switch keyword-only by putting * before it, and name it at the call. Python then rejects send_invoice(invoice, True).
"""Send monthly invoices.""" from billing.mail import send_mail Removed: def send_invoice(invoice, include_pdf: bool = False):Added: def send_invoice(invoice, *, include_pdf: bool = False): attachments = [invoice.render_pdf()] if include_pdf else [] send_mail(invoice.customer.email, invoice.summary(), attachments) def close_month(invoices): for invoice in invoices:Removed: send_invoice(invoice, True)Added: send_invoice(invoice, include_pdf=True)When it can be wrong
- A public library function whose positional signature is part of a published API is reported, even though changing it would break callers.
- Calls in other files are not read, so a private helper called with bare literals from another module is missed.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
Put the marker on the line of the parameter.
Python def send_invoice(invoice, include_pdf: bool = False): # skylos: ignore[SKY-L029][tool.skylos] ignore = ["SKY-L029"]turns the rule off for the project.