SKY-Q701 · Quality, structure and performance
High coupling
Coupling is how many other classes one class depends on. SKY-Q701 counts, for each Python class, the other classes defined in the same file that it inherits from, names in type hints, creates, reads attributes from or uses as decorators, and reports a class that depends on more than 4 of them.
- 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
A class wired to many others breaks when any of them changes, and testing it means building all of them first. In a single file, a class like this is often where the module's responsibilities should have been split.
What Skylos flags
"""Order placement for the shop.""" class Cart: def __init__(self, items): self.items = items class Pricing: def total(self, cart): return sum(item.price for item in cart.items) class TaxTable: rates = {"DE": 0.19, "FR": 0.20} class Inventory: def reserve(self, items): return all(item.in_stock for item in items) class Mailer: def send(self, to, text): print(to, text) class OrderService: def __init__(self): self.pricing = Pricing() self.inventory = Inventory() self.mailer = Mailer() def place(self, cart: Cart, email, country): if not self.inventory.reserve(cart.items): raise ValueError("out of stock") total = self.pricing.total(cart) * (1 + TaxTable.rates[country]) self.mailer.send(email, f"Order total: {total:.2f}") return totalWhat Skylos leaves alone
"""Order placement for the shop.""" class Cart: def __init__(self, items): self.items = items class Pricing: rates = {"DE": 0.19, "FR": 0.20} def total(self, cart, country): net = sum(item.price for item in cart.items) return net * (1 + self.rates[country]) class Inventory: def reserve(self, items): return all(item.in_stock for item in items) class Mailer: def send(self, to, text): print(to, text) class OrderService: def __init__(self): self.pricing = Pricing() self.inventory = Inventory() self.mailer = Mailer() def place(self, cart: Cart, email, country): if not self.inventory.reserve(cart.items): raise ValueError("out of stock") total = self.pricing.total(cart, country) self.mailer.send(email, f"Order total: {total:.2f}") return totalWhy Skylos leaves it alone
Tax now belongs to Pricing, so OrderService depends on 4 classes: Cart, Pricing, Inventory and Mailer. That is the limit, and Skylos reports only counts above it.
How Skylos decides
- Runs with
--quality, on each Python class that has behaviour. Declaration-only classes (fields, enum values, stubs) are not measured. - Collects the classes defined in the same file. A dependency is another of those classes that this class inherits from, names in a type hint, calls (creates), reads an attribute of, or uses as a decorator. Classes imported from other modules are not counted.
- Reports when the number of distinct dependencies is above 4: MEDIUM up to 8, HIGH above 8. The limits are fixed.
- Reports on the
classline, with the count per kind of dependency.
How to fix it
Move each decision to the class that owns its data (tax to Pricing), or pass the collaborators in, so the class talks to fewer others.
"""Order placement for the shop.""" class Cart: def __init__(self, items): self.items = items class Pricing:Removed: def total(self, cart):Removed: return sum(item.price for item in cart.items)Removed: Removed: Removed: class TaxTable: rates = {"DE": 0.19, "FR": 0.20} Removed: Removed: class Inventory:Removed: def reserve(self, items):Removed: return all(item.in_stock for item in items)Removed: Removed: Removed: class Mailer:Removed: def send(self, to, text):Removed: print(to, text)Added: def total(self, cart, country):Added: net = sum(item.price for item in cart.items)Added: return net * (1 + self.rates[country]) class OrderService:Removed: def __init__(self):Removed: self.pricing = Pricing()Removed: self.inventory = Inventory()Removed: self.mailer = Mailer()Added: def __init__(self, pricing, inventory, mailer):Added: self.pricing = pricingAdded: self.inventory = inventoryAdded: self.mailer = mailer def place(self, cart: Cart, email, country): if not self.inventory.reserve(cart.items): raise ValueError("out of stock")Removed: total = self.pricing.total(cart) * (1 + TaxTable.rates[country])Added: total = self.pricing.total(cart, country) self.mailer.send(email, f"Order total: {total:.2f}") return totalWhen it can be wrong
- Only classes of the same file count, so the measure says little about a class whose collaborators live in other modules, and a module that keeps a family of related classes together scores higher.
- A composition root or factory that is meant to wire many classes together is reported.
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
classline (the reported line):Python class OrderService: # skylos: ignore[SKY-Q701] wires the checkout together[tool.skylos] ignore = ["SKY-Q701"]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.