From 2c0d1b3f37b267b6370fc2fd05098d68bc7fea14 Mon Sep 17 00:00:00 2001 From: Artur Shiriev Date: Tue, 7 Jul 2026 22:09:12 +0300 Subject: [PATCH] chore: adopt modern-di 2.25 integration seams Replace the isinstance-on-AbstractProvider dispatch in _resolve_di_params with container.resolve_dependency(...), modern-di's blessed provider-or-type dispatch entry point for integrations. Bump the modern-di floor to >=2.25.0,<3 to require it. --- architecture/injection.md | 4 ++-- modern_di_typer/main.py | 9 +-------- pyproject.toml | 2 +- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/architecture/injection.md b/architecture/injection.md index b6859b0..324ad30 100644 --- a/architecture/injection.md +++ b/architecture/injection.md @@ -38,8 +38,8 @@ The wrapper runs on every invocation: 2. Build the per-command `Scope.REQUEST` container and stash it on `ctx.meta` (see [scopes.md](scopes.md)). 3. If there are `FromDI` parameters, `_resolve_di_params` resolves each from the - command container — `resolve_provider(...)` for provider markers, - `resolve(dependency_type=...)` for bare types — and fills them into the call. + command container via `resolve_dependency(...)` — modern-di's single + provider-or-type dispatch — and fills them into the call. 4. Call the original function; close the command container on return. `FromDI` parameters coexist with ordinary Typer arguments and options: because diff --git a/modern_di_typer/main.py b/modern_di_typer/main.py index 1adf412..54ebebb 100644 --- a/modern_di_typer/main.py +++ b/modern_di_typer/main.py @@ -77,14 +77,7 @@ def _resolve_di_params( cmd_container: Container, di_params: dict[str, _FromDI[typing.Any]], ) -> dict[str, typing.Any]: - return { - name: ( - cmd_container.resolve_provider(marker.provider) - if isinstance(marker.provider, providers.AbstractProvider) - else cmd_container.resolve(dependency_type=marker.provider) - ) - for name, marker in di_params.items() - } + return {name: cmd_container.resolve_dependency(marker.provider) for name, marker in di_params.items()} def inject(func: typing.Callable[..., T]) -> typing.Callable[..., T]: diff --git a/pyproject.toml b/pyproject.toml index dc8b7b9..7bbafcb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ classifiers = [ "Typing :: Typed", "Topic :: Software Development :: Libraries", ] -dependencies = ["typer>=0.9,<1", "modern-di>=2.19.0,<3"] +dependencies = ["typer>=0.9,<1", "modern-di>=2.25.0,<3"] version = "0" [project.urls]