Skip to main content

SKY-CIRC · Quality, structure and performance

Circular dependency

Low

The catalog gives no severity. Every cycle is reported LOW, whatever its length.

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 = false turns 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 --strict fails on it, as on any finding.
Finding type
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

shop/customers.py · PythonReported on line 3
"""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)
shop/orders.py · Python
"""Orders and their totals.""" from shop.customers import Customer  class Order:    def __init__(self, customer: Customer, total: float):        self.customer = customer        self.total = total
shop/__init__.py · Python
"""The shop package."""

What Skylos leaves alone

shop/customers.py · Python
"""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 order

shop/orders.py: same as in the flagged example.

shop/__init__.py: same as in the flagged example.

Why 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

  1. Runs on every scan, with or without --quality, unless check_circular = false is set under [tool.skylos]. Python and JS/TS files form separate graphs.
  2. For Python, collects the import and from … import statements written directly at the top level of each module, resolving relative imports. Imports inside functions, classes, if TYPE_CHECKING: blocks or try blocks are not read.
  3. 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.
  4. 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.
  5. Reports at the import that closes the loop with the lowest file path and line number among the loop's imports.
  6. For JS/TS, an edge is a literal import, export … from or top-level require() that resolves to another scanned JS/TS file or a Vue, Svelte or Astro component script. import type, export type, all-type clauses, import() and a require() 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_files lists 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.

shop/customers.py · Python · the fix, against the flagged file
"""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, try blocks or conditional blocks, and loops that cross from one language to another. A JS/TS import whose bindings are used only as types, without the type keyword, 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 = false under [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] tracked
  • After skylos baseline ., a scan with --baseline hides the existing loop while its directed imports stay the same. It still matches when source line numbers change.

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