SKY-Q502 · Quality, structure and performance
File too large
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
--qualityscan but not listed by default. It is listed, and counted towardmax_quality, with--all-adviceor when the rule is named in[tool.skylos.gate] rules. - Finding type
- advice
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
"""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}"[tool.skylos]god_file_max_top_level_definitions = 6What Skylos leaves alone
"""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"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
- Runs with
--quality, once per Python module. - 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.
- Declaration-only classes (fields, enum values, stubs and a plain
__init__that copies its parameters) and@overloadsignatures that repeat a real function are not counted. - Compares the counts with
god_file_max_lines(default 500),god_file_max_definitions(default 40) andgod_file_max_top_level_definitions(default 25) under[tool.skylos], and reports when any count is above its limit. - Skips test code (test folders,
test_*.pyand*_test.pymodules that define tests, files pytest is configured to collect),examplesandbenchmarksfolders, a top-leveldocsfolder and the rootsetup.py. - 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.
"""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 splitignore = ["SKY-Q502"]under[tool.skylos]turns the rule off for the project; highergod_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.