SKY-CIRC · Quality, structure and performance
Circular dependency
A circular dependency is a loop of imports: module A imports B and B imports A, directly or through other modules. SKY-CIRC reports each loop of module-level Python imports and each group of JavaScript or TypeScript files whose load-time imports form loops. JSON and SARIF reports identify the contributing import sites. A diff scan includes the finding when a changed line matches one of those sites.
- Languages
- Python, TypeScript, JavaScript
- Turned on by
- every scan, including a plain
skylos .;check_circular = falseturns it off - Quality gate
- listed, not counted by the gate (full and diff scans). Reported by every scan, but no
[tool.skylos.gate]limit counts it.skylos . --gate --strictfails on it, as on any finding. - Finding type
- review
Why it matters
Python runs a module while importing it, so in a loop one module is used before it has finished loading: ImportError: cannot import name 'Order' from partially initialized module. Even when the import order happens to work, the two modules can no longer be changed, tested or moved apart from each other.
What Skylos flags
"""Customers and their order history.""" from shop.orders import Order class Customer: def __init__(self, email: str): self.email = email self.orders: list[Order] = [] def lifetime_value(self) -> float: return sum(order.total for order in self.orders)"""Orders and their totals.""" from shop.customers import Customer class Order: def __init__(self, customer: Customer, total: float): self.customer = customer self.total = total"""The shop package."""What Skylos leaves alone
"""Customers and their order history.""" class Customer: def __init__(self, email: str): self.email = email self.orders = [] def place_order(self, total: float): from shop.orders import Order order = Order(self, total) self.orders.append(order) return orderWhy Skylos leaves it alone
customers imports orders only inside a function, which runs after both modules have loaded, so importing either module cannot fail. Skylos reads only the imports written at the top level of a module.
How Skylos decides
- Runs on every scan, with or without
--quality, unlesscheck_circular = falseis set under[tool.skylos]. Python and JS/TS files form separate graphs. - For Python, collects the
importandfrom … importstatements written directly at the top level of each module, resolving relative imports. Imports inside functions, classes,if TYPE_CHECKING:blocks ortryblocks are not read. - Keeps imports that resolve to a module of the scanned project. Within one top-level package each edge goes to the exact module; an import into another top-level package of the project counts as an edge to that package.
- Finds every simple loop in that graph and reports each loop once, LOW. The finding names the modules in order and suggests the module with the fewest imports pointing at it, relative to its own imports, as the place to break the loop.
- Reports at the import that closes the loop with the lowest file path and line number among the loop's imports.
- For JS/TS, an edge is a literal
import,export … fromor top-levelrequire()that resolves to another scanned JS/TS file or a Vue, Svelte or Astro component script.import type,export type, all-typeclauses,import()and arequire()inside a function do not run when the file loads and are not edges. Each strongly connected group of files is reported once, with the shortest loop through its first file in path order;component_fileslists a larger group.
How to fix it
When one side needs the other only for type hints, import it under if TYPE_CHECKING: with postponed annotations. When both really need each other at run time, move the shared part into a third module that both import.
"""Customers and their order history.""" Removed: from shop.orders import OrderAdded: from __future__ import annotations Added: from typing import TYPE_CHECKING Added: if TYPE_CHECKING:Added: from shop.orders import OrderAdded: Added: class Customer: def __init__(self, email: str): self.email = email self.orders: list[Order] = [] def lifetime_value(self) -> float: return sum(order.total for order in self.orders)When it can be wrong
- A loop that works because the imports run in a safe order, or because one side only imports names it uses later, is still reported.
- It misses Python loops created by imports inside functions,
tryblocks or conditional blocks, and loops that cross from one language to another. A JS/TS import whose bindings are used only as types, without thetypekeyword, still counts as an edge.
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
check_circular = falseunder[tool.skylos]turns the check off for the project:TOML [tool.skylos]check_circular = false[tool.skylos] ignore = ["SKY-CIRC"]does not silence it: the loop is still reported.An inline marker does not work either; with this comment on the reported import, the loop is still reported:
Python from shop.orders import Order # skylos: ignore[SKY-CIRC] trackedAfter
skylos baseline ., a scan with--baselinehides the existing loop while its directed imports stay the same. It still matches when source line numbers change.