Skip to content

Circular Imports and Import Resolution Issue in Pneuma #1

@ogiorgil

Description

@ogiorgil

I am encountering two main issues related to import management:

  1. Circular Import: I want to import from a sibling package. If I do from pneuma.utils.response import Response, ResponseStatus from registration.py and try to run the script directly, ModuleNotFoundError: No module named 'pneuma' occurs. Additionally, if pneuma.py is run, ImportError: cannot import name 'Registration' from partially initialized module 'registration.registration' (most likely due to a circular import) (xxx\Pneuma\pneuma\registration\registration.py) occurs.
  2. Relative import error: If I do from ..utils.response import Response, ResponseStatus instead, ImportError: attempted relative import with no known parent package occurs, both when running the scripts directly and running pneuma.py

Below is the current simplified project structure:

pneuma/
├── __init__.py
├── registration/
│   ├── __init__.py
│   ├── registration.py
│   └── helper.py
├── utils/
│   ├── __init__.py
│   ├── response.py
└── pneuma.py

Right now, the fix is doing sys.path.append(str(Path(__file__).resolve().parent.parent)) and importing with from utils.response import Response, ResponseStatus to import from sibling packages.

Request for help:

  • Suggestions for restructuring the code to avoid circular imports.
  • Best practices for import management in this project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions