Skip to main content

SKY-Q701 · Quality, structure and performance

High coupling

Varies

The catalog gives no severity. MEDIUM for a class that depends on 5 to 8 other classes of its file, HIGH from 9.

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-advice or when the rule is named in [tool.skylos.gate] rules.
Finding type
advice
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

app/orders.py · PythonReported on line 28
"""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 total

What Skylos leaves alone

app/orders.py · Python
"""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 total

Why 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

  1. Runs with --quality, on each Python class that has behaviour. Declaration-only classes (fields, enum values, stubs) are not measured.
  2. 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.
  3. Reports when the number of distinct dependencies is above 4: MEDIUM up to 8, HIGH above 8. The limits are fixed.
  4. Reports on the class line, 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.

app/orders.py · Python · the fix, against the flagged file
"""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 total

When 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 class line (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.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.