Skip to content

Conversation

@Zehen-249
Copy link
Contributor

The Common.py was importing

from .utils.common.component import *

but was never used

This unnecessary import introduced a circular dependency between Common.py and component.py.
When Common.py was imported, it tried to load component.py.
component.py, in turn, imports from Common.py.

This created a circular import loop, which caused runtime errors during execution (e.g., when running tension_bolted_test.py).

  • Verified with an AST-based static analysis script that Common.py does not use any symbols from component.py.
  • After removal, the circular import issue is resolved, and all tests/scripts execute successfully without errors.
import ast
from pathlib import Path

common_path = Path("osdag/Common.py")
component_path = Path("osdag/utils/common/component.py")

def get_defined_names(path):
    with open(path, "r", encoding="utf-8") as f:
        tree = ast.parse(f.read(), filename=str(path))
    defined = set()
    for node in ast.walk(tree):
        if isinstance(node, (ast.FunctionDef, ast.ClassDef)):
            defined.add(node.name)
        elif isinstance(node, ast.Assign):  # top-level constants/variables
            for target in node.targets:
                if isinstance(target, ast.Name):
                    defined.add(target.id)
    return defined

def get_used_names_with_lines(path):
    with open(path, "r", encoding="utf-8") as f:
        tree = ast.parse(f.read(), filename=str(path))
    used = {}
    for node in ast.walk(tree):
        if isinstance(node, ast.Name):
            used.setdefault(node.id, []).append(node.lineno)
    return used

# Get definitions and usages
component_defs = get_defined_names(component_path)
common_used = get_used_names_with_lines(common_path)

# Intersect
used_from_component = {name: common_used[name] for name in component_defs if name in common_used}

print("Names from component.py actually used in Common.py (with line numbers):")
for name, lines in used_from_component.items():
    print(f"  {name} -> lines {lines}")

this script was used to check the variables, methods and classes being used from component.py in Common.py
can be used in future for resolving any other circular import!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant