It happened to me a couple of times that when working on a new feature / making changes in the code, I made a new import across our sub-modules and ran into the circular import error.
Often, we use imports for the sake of type hinting, meaning some imports inside our codebase are not needed during runtime. Some circular imports could be prevented in the future by importing such modules / classes only when type checking is done. For example:
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from packit_service.worker.helpers.testing_farm import (
DownstreamTestingFarmJobHelper,
TestingFarmJobHelper,
)
This would require the imported classed being referred to as "DownstreamTestingFarmJobHelper" and "TestingFarmJobHelper" inside type hints (with the quotation marks). In order not to be forced to use quotation marks, it is possible to define the following at the start of the file:
from __future__ import annotations
However, doing so will resolve in ruff complaining when running pre-commit, so the check would either have to be disabled or we just have to use quotation marks.
UP045 Use `X | None` for type annotations
TODO:
It happened to me a couple of times that when working on a new feature / making changes in the code, I made a new import across our sub-modules and ran into the circular import error.
Often, we use imports for the sake of type hinting, meaning some imports inside our codebase are not needed during runtime. Some circular imports could be prevented in the future by importing such modules / classes only when type checking is done. For example:
This would require the imported classed being referred to as "DownstreamTestingFarmJobHelper" and "TestingFarmJobHelper" inside type hints (with the quotation marks). In order not to be forced to use quotation marks, it is possible to define the following at the start of the file:
However, doing so will resolve in
ruffcomplaining when runningpre-commit, so the check would either have to be disabled or we just have to use quotation marks.TODO: