Skip to main content

SKY-Q501 · Quality, structure and performance

God class

Medium

The catalog gives no severity. Both of the rule's findings, too many methods and too many attributes, are reported MEDIUM.

A god class is one class that holds too much of a program's state and behaviour. SKY-Q501 reports a Python class with more than 20 ordinary methods or more than 15 instance attributes (fields set through self).

Languages
Python
Quality gate
counted toward the gate limits (full and diff scans). Advice that is measured on every --quality scan but 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

Every method of such a class can read and change every field, so a change to one feature (coupons, say) can break another (payment retries), and tests need the whole object set up just to check one step.

What Skylos flags

app/checkout.py · PythonReported on line 4
"""Checkout flow for the web shop."""  class CheckoutSession:    def __init__(self, cart, customer, payments, mailer):        self.cart = cart        self.customer = customer        self.payments = payments        self.mailer = mailer        self.coupon = None        self.discount = 0        self.shipping_method = "standard"        self.shipping_cost = 0        self.tax = 0        self.total = 0        self.address = None        self.payment_intent = None        self.receipt_email = customer.email        self.status = "open"        self.errors = []        self.attempts = 0     def apply_coupon(self, code):        self.coupon = code        self.discount = self.cart.subtotal * 0.1     def charge(self):        self.attempts += 1        self.total = self.cart.subtotal - self.discount + self.shipping_cost        self.payment_intent = self.payments.charge(self.customer, self.total)        self.status = "paid"        self.mailer.send_receipt(self.receipt_email, self.total)

What Skylos leaves alone

app/models.py · Python
"""Order records shared by checkout and reporting.""" from dataclasses import dataclass, fieldfrom datetime import datetime  @dataclassclass OrderRecord:    id: int    customer_id: int    email: str    currency: str    subtotal: float    discount: float    shipping_cost: float    tax: float    total: float    coupon: str | None    shipping_method: str    street: str    city: str    postcode: str    country: str    status: str    created: datetime    notes: list[str] = field(default_factory=list)

Why Skylos leaves it alone

The record has 18 fields, but they are declared in the class body, not set through self in a method, and it has no methods of its own. Skylos counts only attributes that methods assign, so a plain data record is not reported.

How Skylos decides

  1. Runs with --quality, on Python classes.
  2. Counts the methods defined in the class body. Dunder methods such as __init__, __len__ and __getitem__ are not counted, and neither are @overload signatures that have an implementation in the class.
  3. Counts instance attributes: the distinct names the instance methods assign through self (self.status = ..., self.attempts += 1). Fields declared in the class body are not counted.
  4. Reports MEDIUM when there are more than 20 methods, and separately MEDIUM when there are more than 15 instance attributes. These limits are fixed; no setting changes them.
  5. Skips declaration-only classes (fields, stubs and a plain __init__ that copies its parameters), test classes that pytest collects or that follow the Test naming in test files, and files in examples, benchmarks and top-level docs folders and the root setup.py.
  6. Reports on the class line.

How to fix it

Move each group of fields that change together, and the methods that use them, into its own class, and let the original class hold that object. Here the price fields become a Pricing object.

app/checkout.py · Python · the fix, against the flagged file
"""Checkout flow for the web shop."""  Added: class Pricing:Added:     def __init__(self, cart):Added:         self.cart = cartAdded:         self.coupon = NoneAdded:         self.discount = 0Added:         self.shipping_cost = 0Added:         self.tax = 0Added:  Added:     def apply_coupon(self, code):Added:         self.coupon = codeAdded:         self.discount = self.cart.subtotal * 0.1Added:  Added:     def total(self):Added:         return self.cart.subtotal - self.discount + self.shipping_cost + self.taxAdded:  Added:  class CheckoutSession:    def __init__(self, cart, customer, payments, mailer):Removed:         self.cart = cartAdded:         self.pricing = Pricing(cart)        self.customer = customer        self.payments = payments        self.mailer = mailerRemoved:         self.coupon = NoneRemoved:         self.discount = 0        self.shipping_method = "standard"Removed:         self.shipping_cost = 0Removed:         self.tax = 0Removed:         self.total = 0        self.address = None        self.payment_intent = NoneRemoved:         self.receipt_email = customer.email        self.status = "open"        self.errors = []        self.attempts = 0 Removed:     def apply_coupon(self, code):Removed:         self.coupon = codeRemoved:         self.discount = self.cart.subtotal * 0.1Removed:      def charge(self):        self.attempts += 1Removed:         self.total = self.cart.subtotal - self.discount + self.shipping_costRemoved:         self.payment_intent = self.payments.charge(self.customer, self.total)Added:         total = self.pricing.total()Added:         self.payment_intent = self.payments.charge(self.customer, total)        self.status = "paid"Removed:         self.mailer.send_receipt(self.receipt_email, self.total)Added:         self.mailer.send_receipt(self.customer.email, total)

When it can be wrong

  • A facade or a framework class that must expose many small methods (an admin class, a test helper, an API client with one method per endpoint) is reported even when each method is trivial.
  • Attributes set from outside the class, or declared only in the class body, are not counted, so a class can grow past the limit unseen.

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 CheckoutSession:  # skylos: ignore[SKY-Q501] split in the checkout rewrite
  • [tool.skylos] ignore = ["SKY-Q501"] 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.