Skip to content

Commit 91830aa

Browse files
committed
fix: resolve circular import and configure Python source directory
Configuration (pyproject.toml): - Add [tool.setuptools] with package-dir = {"" = "python"} - Add mypy_path = "python" to [tool.mypy] - Tells IDEs that python/ is the source root (not python/rivet_di) Circular Import Fix (python/rivet_di/decorators.py): - Import Scope from rivet_di.scope module directly - Avoids going through rivet_di.__init__.py during import - Keeps type safety with Scope enum The issue was that importing 'from rivet_di import Scope' triggers __init__.py loading, but __init__.py also imports decorators, creating a cycle. By importing from rivet_di.scope directly, we bypass __init__.py. All behave tests passing (25/25 steps)
1 parent d216da6 commit 91830aa

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ python-source = "python"
5151
module-name = "rivet_di._rivet_core"
5252
features = ["pyo3/extension-module"]
5353

54+
[tool.setuptools]
55+
package-dir = {"" = "python"}
56+
5457
[tool.pytest.ini_options]
5558
testpaths = ["tests"]
5659
python_files = ["test_*.py", "*_test.py"]
@@ -61,6 +64,7 @@ addopts = [
6164

6265
[tool.mypy]
6366
python_version = "3.11"
67+
mypy_path = "python"
6468
warn_return_any = true
6569
warn_unused_configs = true
6670
disallow_untyped_defs = true

python/rivet_di/decorators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ def component(
1414
Mark a class as a dependency injection component.
1515
1616
Args:
17-
scope: Lifecycle scope (SINGLETON or FACTORY)
17+
scope: Lifecycle scope (SINGLETON or FACTORY), defaults to SINGLETON
1818
1919
Returns:
2020
Decorated class with DI metadata
2121
2222
Example:
23+
>>> from rivet_di import Scope
2324
>>> @component(scope=Scope.SINGLETON)
2425
... class DatabaseConnection:
2526
... pass

0 commit comments

Comments
 (0)