Skip to main content

SKY-Q502 · Quality, structure and performance

File too large

Varies

The catalog gives no severity. MEDIUM when one limit is exceeded by less than half; HIGH when a count reaches 1.5 times its limit or two or more limits are exceeded.

SKY-Q502 reports a Python module that has grown too big to hold one responsibility: more than 500 lines of implementation code, more than 40 classes, functions and methods, or more than 25 top-level definitions. The examples lower the top-level limit to 6 in pyproject.toml so they stay short.

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

A grab-bag module such as utils.py is imported by everything, so a change to one helper rebuilds and retests the world, merges conflict often, and nobody can tell which helpers are still used.

What Skylos flags

app/utils.py · PythonReported on line 1
"""Helpers used across the shop.""" import reimport timefrom decimal import Decimal  def slugify(title):    return re.sub(r"[^a-z0-9]+", "-", title.lower()).strip("-")  def parse_money(text):    return Decimal(text.replace(",", "").lstrip("$"))  def format_money(amount, currency="USD"):    return f"{amount:,.2f} {currency}"  def chunked(items, size):    return [items[i : i + size] for i in range(0, len(items), size)]  def retry(call, attempts=3, delay=0.5):    for attempt in range(attempts):        try:            return call()        except ConnectionError:            if attempt == attempts - 1:                raise            time.sleep(delay)  def mask_email(email):    name, _, domain = email.partition("@")    return f"{name[:1]}***@{domain}"  def send_welcome_email(mailer, customer):    mailer.send(customer.email, "Welcome!", f"Hi {customer.first_name}")  def order_reference(order_id):    return f"ORD-{order_id:08d}"
pyproject.toml · TOML
[tool.skylos]god_file_max_top_level_definitions = 6

What Skylos leaves alone

app/statuses.py · Python
"""Status values stored in the database.""" from enum import Enum  class OrderStatus(str, Enum):    OPEN = "open"    PAID = "paid"    SHIPPED = "shipped"  class PaymentStatus(str, Enum):    PENDING = "pending"    CAPTURED = "captured"    REFUNDED = "refunded"  class ShipmentStatus(str, Enum):    LABELLED = "labelled"    IN_TRANSIT = "in_transit"    DELIVERED = "delivered"  class RefundReason(str, Enum):    DAMAGED = "damaged"    LATE = "late"    OTHER = "other"  class Carrier(str, Enum):    DHL = "dhl"    UPS = "ups"  class Currency(str, Enum):    USD = "USD"    EUR = "EUR"  class Channel(str, Enum):    WEB = "web"    APP = "app"  class Region(str, Enum):    EU = "eu"    US = "us"

pyproject.toml: same as in the flagged example.

Why Skylos leaves it alone

The module also has 8 top-level classes, but each one only declares values and has no behaviour. Skylos leaves such declaration-only classes out of every count, so a catalogue of enums or records is not a god file.

How Skylos decides

  1. Runs with --quality, once per Python module.
  2. Counts three things. Implementation code lines: lines with code, not blank, comment or docstring lines, leaving out declaration-only classes and the inner lines of literal lists, tuples, sets and dicts. All definitions: classes, functions and methods that are not inside a function body. Top-level definitions: classes and functions directly in the module.
  3. Declaration-only classes (fields, enum values, stubs and a plain __init__ that copies its parameters) and @overload signatures that repeat a real function are not counted.
  4. Compares the counts with god_file_max_lines (default 500), god_file_max_definitions (default 40) and god_file_max_top_level_definitions (default 25) under [tool.skylos], and reports when any count is above its limit.
  5. Skips test code (test folders, test_*.py and *_test.py modules that define tests, files pytest is configured to collect), examples and benchmarks folders, a top-level docs folder and the root setup.py.
  6. Reports on line 1 of the file, naming every exceeded limit. HIGH when the worst count is at least 1.5 times its limit or two limits are exceeded, otherwise MEDIUM.

How to fix it

Split the module by responsibility: money helpers in one module, text helpers in another, email in the module that sends mail. Each module then has a name that says what is in it.

Fix · Python
"""Money parsing and formatting.""" from decimal import Decimal  def parse_money(text):    return Decimal(text.replace(",", "").lstrip("$"))  def format_money(amount, currency="USD"):    return f"{amount:,.2f} {currency}"

When it can be wrong

  • A module that is large on purpose, such as a generated client or a single-file library meant to be copied, is reported.
  • A long module of small, closely related functions (a parser with one function per grammar rule) is reported although splitting it would not make it clearer.

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 line 1 of the file, the reported line:

    Python
    """Helpers used across the shop."""  # skylos: ignore[SKY-Q502] being split
  • ignore = ["SKY-Q502"] under [tool.skylos] turns the rule off for the project; higher god_file_max_* values raise the limits instead. A baseline accepts existing findings, but it records the absolute file path and the line, so an entry stops matching when the checkout moves.

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