SKY-Q806 · Quality, structure and performance
Opaque identifier
An opaque identifier is a placeholder name such as tmp, obj, val or data given to a value whose meaning is plain from where it comes from. SKY-Q806 reports such a local variable when the right-hand side names the value through a dictionary key and the variable lives long enough for the name to matter.
- Languages
- Python
- Quality gate
- counted toward the gate limits (full and diff scans). A measurement, not listed by default. It is listed, and counted toward
max_quality, with--all-adviceor when the rule is named in[tool.skylos.gate] rules. - Finding type
- advice
Why it matters
Eight lines after tmp = event[...]["customer_email"], a reader sees mailer.send(tmp, ...) and has to scroll back to learn that tmp is an e-mail address. Names that say what a value is make review and later changes faster and safer.
What Skylos flags
"""Stripe webhook handlers.""" import logging log = logging.getLogger(__name__) def handle_checkout_completed(event, db, mailer): tmp = event["data"]["object"]["customer_email"] order = db.find_order(event["data"]["object"]["client_reference_id"]) if not tmp: return False order.contact_email = tmp db.save(order) mailer.send(tmp, "Thanks for your order") log.info("receipt sent to %s", tmp) return TrueWhat Skylos leaves alone
"""Stripe webhook handlers.""" def handle_checkout_completed(event, db): tmp = event["data"]["object"]["customer_email"] db.update_contact(event["data"]["object"]["client_reference_id"], tmp) return TrueWhy Skylos leaves it alone
The same placeholder is used once, on the very next line, where its origin is still in view. Skylos reports a placeholder name only when its last use is at least five lines after the assignment.
How Skylos decides
- Runs with
--quality, on the local variables of Python functions. Files intest,testsorcorpusfolders andtest_*.pyor*_test.pyfiles are skipped. - The name must be a placeholder:
tmp,temp,var,val,obj,thing,stuff,out,retor a single letter (strong), ordata,result,results,value,item,itemsorinfo(weak). Names starting with_, upper-case names and common short names such asidandpkare not placeholders. - The right-hand side must name the value through a key:
x["customer_email"]orx.get("customer_email"). Skylos builds a suggested name from those words and drops the finding when the suggestion is no clearer than the current name or the right side already uses the current name. - The variable must be used, with its last use at least 5 lines after the assignment. A score adds the name's opacity, the strength of the key evidence and the usage (a long span, three or more uses, use in a condition, a call or a
return); it must reach 6, or 7 for a weak name. - Reports LOW on the assignment line, with the suggested name.
How to fix it
Name the variable after what it holds; the key it comes from is usually the right name.
"""Stripe webhook handlers.""" import logging log = logging.getLogger(__name__) def handle_checkout_completed(event, db, mailer):Removed: tmp = event["data"]["object"]["customer_email"]Added: customer_email = event["data"]["object"]["customer_email"] order = db.find_order(event["data"]["object"]["client_reference_id"])Removed: if not tmp:Added: if not customer_email: return FalseRemoved: order.contact_email = tmpAdded: order.contact_email = customer_email db.save(order)Removed: mailer.send(tmp, "Thanks for your order")Removed: log.info("receipt sent to %s", tmp)Added: mailer.send(customer_email, "Thanks for your order")Added: log.info("receipt sent to %s", customer_email) return TrueWhen it can be wrong
- A generic name in truly generic code, such as
datain a function that forwards any payload, can be reported when it is read from a named key. - It misses placeholder names whose value comes from a function call without a key, such as
tmp = load_invoice(invoice_id).
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
On the assignment line (the reported line):
Python tmp = event["data"]["object"]["customer_email"] # skylos: ignore[SKY-Q806] legacy[tool.skylos] ignore = ["SKY-Q806"]turns the rule off for the project. A baseline accepts existing findings, but it records the absolute file path and the line, so an entry stops matching when the checkout moves or the line shifts.