Skip to main content

SKY-Q702 · Quality, structure and performance

Low cohesion

Varies

The catalog gives no severity. MEDIUM for 3 or 4 unconnected method groups, HIGH from 5.

A cohesive class is one whose methods work on the same data. SKY-Q702 splits a Python class's methods into groups that share instance attributes or call each other (a measure called LCOM4) and reports a class with more than 2 groups that have nothing in common.

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

Unconnected groups are separate jobs sharing one name. Every user of the class depends on all of them, a change to the mail settings means retesting database code, and the class keeps growing because it is the obvious place for "one more helper".

What Skylos flags

app/toolkit.py · PythonReported on line 9
"""Shop helpers that grew into one class.""" import smtplibimport sqlite3 FIND_ORDER = "SELECT * FROM orders WHERE id = ?"  class ShopToolkit:    def open_database(self, path):        self.connection = sqlite3.connect(path)     def find_order(self, order_id):        return self.connection.execute(FIND_ORDER, (order_id,)).fetchone()     def configure_mail(self, host, sender):        self.smtp_host = host        self.sender = sender     def send_receipt(self, to, text):        with smtplib.SMTP(self.smtp_host) as smtp:            smtp.sendmail(self.sender, [to], text)     def reset_counters(self):        self.page_views = 0     def count_page_view(self):        self.page_views += 1        return self.page_views

What Skylos leaves alone

app/toolkit.py · Python
"""Shop helpers that grew into one class.""" import smtplibimport sqlite3 FIND_ORDER = "SELECT * FROM orders WHERE id = ?"  class ShopToolkit:    def open_database(self, path):        self.connection = sqlite3.connect(path)     def find_order(self, order_id):        return self.connection.execute(FIND_ORDER, (order_id,)).fetchone()     def configure_mail(self, host, sender):        self.smtp_host = host        self.sender = sender     def send_receipt(self, to, text):        with smtplib.SMTP(self.smtp_host) as smtp:            smtp.sendmail(self.sender, [to], text)

Why Skylos leaves it alone

Two unconnected groups remain, database and mail. That is the limit; Skylos reports a class only from three groups.

How Skylos decides

  1. Runs with --quality, on Python classes outside test code, examples, benchmarks, a top-level docs folder and the root setup.py. Protocol classes and classes whose methods are all abstract are skipped.
  2. Builds a graph of the class's methods: two methods are connected when they use the same instance attribute or one calls the other through self. __init__ counts like any method, so one that sets every attribute joins all the groups. Methods that use no instance state are left out.
  3. Reports when the number of separate groups is above 2 and at least two of them use attributes the class sets itself. Dataclasses, attrs classes, pydantic models, TypedDict and NamedTuple need more than 6 groups.
  4. Reports on the class line, MEDIUM for 3 or 4 groups and HIGH above 4, and lists up to four groups with their methods. The limits are fixed.

How to fix it

Give each group its own class, named after its job, and let callers use only the one they need.

app/toolkit.py · Python · the fix, against the flagged file
Removed: """Shop helpers that grew into one class."""Added: """Order lookups, receipts and page statistics.""" import smtplibimport sqlite3 FIND_ORDER = "SELECT * FROM orders WHERE id = ?"  Removed: class ShopToolkit:Removed:     def open_database(self, path):Added: class OrderStore:Added:     def __init__(self, path):        self.connection = sqlite3.connect(path)     def find_order(self, order_id):        return self.connection.execute(FIND_ORDER, (order_id,)).fetchone() Removed:     def configure_mail(self, host, sender):Added:  Added: class ReceiptMailer:Added:     def __init__(self, host, sender):        self.smtp_host = host        self.sender = sender     def send_receipt(self, to, text):        with smtplib.SMTP(self.smtp_host) as smtp:            smtp.sendmail(self.sender, [to], text) Removed:     def reset_counters(self):Added:  Added: class PageCounter:Added:     def __init__(self):        self.page_views = 0     def count_page_view(self):        self.page_views += 1        return self.page_views

When it can be wrong

  • A constructor that assigns every attribute connects all methods, so a class with unrelated jobs set up in __init__ is not reported.
  • A facade that deliberately groups unrelated operations behind one object, such as an SDK client, 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 ShopToolkit:  # skylos: ignore[SKY-Q702] split tracked in SHOP-142
  • [tool.skylos] ignore = ["SKY-Q702"] 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.