Skip to content

Use uncalled-for for dependency injection plumbing#353

Merged
chrisguidry merged 5 commits intomainfrom
use-uncalled-for
Feb 27, 2026
Merged

Use uncalled-for for dependency injection plumbing#353
chrisguidry merged 5 commits intomainfrom
use-uncalled-for

Conversation

@chrisguidry
Copy link
Owner

@chrisguidry chrisguidry commented Feb 25, 2026

Docket's DI engine was extracted into the standalone uncalled-for library. This swaps out all the internal DI plumbing — parameter introspection, dependency resolution, validation, Depends(), Shared, SharedContext — for imports from that package.

The public API is unchanged; everything is re-exported from docket.dependencies exactly as before. The docket-specific bits (ContextVars, Retry, Perpetual, ConcurrencyLimit, etc.) stay in docket.

The three ambient ContextVars (current_docket, current_worker, current_execution) are now module-level variables in _base.py rather than class attributes on a custom Dependency subclass, so Dependency is just a direct re-export of uncalled_for.Dependency.

Net result: −394 lines, +167 lines across the dependencies package.

Closes #352

🤖 Generated with Claude Code

Docket's DI engine was extracted into the standalone `uncalled-for` library
(https://pypi.org/project/uncalled-for/). This swaps out all the internal DI
plumbing — parameter introspection, dependency resolution, validation,
`Depends()`, `Shared`, `SharedContext` — for imports from that package.

The public API is unchanged; everything is re-exported from `docket.dependencies`
exactly as before. The docket-specific bits (ContextVars, Retry, Perpetual,
ConcurrencyLimit, etc.) stay in docket.

The three ambient ContextVars (`current_docket`, `current_worker`,
`current_execution`) are now module-level variables in `_base.py` rather than
class attributes on a custom `Dependency` subclass, so `Dependency` is just a
direct re-export of `uncalled_for.Dependency`.

Net result: −394 lines, +167 lines across the dependencies package.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@read-the-docs-community
Copy link

read-the-docs-community bot commented Feb 25, 2026

Documentation build overview

📚 docket | 🛠️ Build #31588698 | 📁 Comparing ac7ec77 against latest (cd4d96b)


🔍 Preview build

Show files changed (2 files in total): 📝 2 modified | ➕ 0 added | ➖ 0 deleted
File Status
api-reference/index.html 📝 modified
dependency-injection/index.html 📝 modified

@codecov-commenter
Copy link

codecov-commenter commented Feb 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (cd4d96b) to head (ac7ec77).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##              main      #353    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           99        99            
  Lines         3098      2969   -129     
  Branches        27        26     -1     
==========================================
- Hits          3098      2969   -129     
Flag Coverage Δ
cli-python-3.10 100.00% <ø> (ø)
cli-python-3.11 100.00% <ø> (ø)
cli-python-3.12 100.00% <ø> (ø)
cli-python-3.13 100.00% <ø> (ø)
cli-python-3.14 100.00% <ø> (ø)
python-3.10 100.00% <100.00%> (ø)
python-3.11 97.89% <100.00%> (-0.14%) ⬇️
python-3.12 100.00% <100.00%> (ø)
python-3.13 100.00% <100.00%> (ø)
python-3.14 100.00% <100.00%> (ø)
windows-python-3.10 100.00% <100.00%> (ø)
windows-python-3.11 97.80% <100.00%> (-0.11%) ⬇️
windows-python-3.12 100.00% <100.00%> (ø)
windows-python-3.13 100.00% <100.00%> (ø)
windows-python-3.14 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/docket/dependencies/__init__.py 100.00% <ø> (ø)
src/docket/dependencies/_base.py 100.00% <100.00%> (ø)
src/docket/dependencies/_concurrency.py 100.00% <ø> (ø)
src/docket/dependencies/_contextual.py 100.00% <100.00%> (ø)
src/docket/dependencies/_cron.py 100.00% <ø> (ø)
src/docket/dependencies/_functional.py 100.00% <100.00%> (ø)
src/docket/dependencies/_perpetual.py 100.00% <ø> (ø)
src/docket/dependencies/_progress.py 100.00% <ø> (ø)
src/docket/dependencies/_resolution.py 100.00% <100.00%> (ø)
src/docket/dependencies/_retry.py 100.00% <ø> (ø)
... and 7 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d3ea664fa5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

chrisguidry and others added 2 commits February 25, 2026 16:39
SharedContext no longer needs a docket-specific subclass. The worker now
sets current_docket/current_worker ContextVars directly in its own
__aenter__, and SharedContext is just a re-export of uncalled_for's.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
FastMCP accesses Dependency.execution.get() to retrieve the current
execution context.  Now that Dependency comes from uncalled-for and the
ContextVars are module-level, patch them back onto the class so existing
consumers keep working.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
chrisguidry added a commit to PrefectHQ/fastmcp that referenced this pull request Feb 25, 2026
FastMCP vendored a minimal DI engine extracted from Docket (~164 lines)
with try/except fallback patterns everywhere. The `uncalled-for` package
is a clean, typed extraction of this same system, and since Docket will
also depend on it (chrisguidry/docket#353), `uncalled_for.Dependency`
becomes the single canonical base class.

This deletes the `_vendor/docket_di/` directory, replaces all the
try/except import patterns with direct `uncalled_for` imports, and
updates the `Dependency.execution` → `current_execution` ContextVar
references to match the Docket branch. The `Progress` class now
delegates to an internal impl and returns `self` from `__aenter__`
(matching Docket's pattern) so that ty's generic resolution works
without `type: ignore` suppressions.

Temporarily points pydocket at the `use-uncalled-for` branch so both
sides can be validated together in CI.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
chrisguidry and others added 2 commits February 26, 2026 08:51
Adds a note to the dependency injection docs that the DI system is now
built on uncalled-for as of 0.18.0, with links to its GitHub and PyPI.

Also updates the "Subclassing Dependency" section to show the new
module-level ContextVars (current_docket, current_worker,
current_execution) instead of the old class-attribute pattern, and adds
an example of using the higher-level contextual dependencies instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chrisguidry chrisguidry merged commit 3484ea9 into main Feb 27, 2026
92 of 93 checks passed
@chrisguidry chrisguidry deleted the use-uncalled-for branch February 27, 2026 14:18
chrisguidry added a commit to PrefectHQ/fastmcp that referenced this pull request Feb 27, 2026
FastMCP vendored a minimal DI engine extracted from Docket (~164 lines)
with try/except fallback patterns everywhere. The `uncalled-for` package
is a clean, typed extraction of this same system, and since Docket will
also depend on it (chrisguidry/docket#353), `uncalled_for.Dependency`
becomes the single canonical base class.

This deletes the `_vendor/docket_di/` directory, replaces all the
try/except import patterns with direct `uncalled_for` imports, and
updates the `Dependency.execution` → `current_execution` ContextVar
references to match the Docket branch. The `Progress` class now
delegates to an internal impl and returns `self` from `__aenter__`
(matching Docket's pattern) so that ty's generic resolution works
without `type: ignore` suppressions.

Temporarily points pydocket at the `use-uncalled-for` branch so both
sides can be validated together in CI.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
chrisguidry added a commit to PrefectHQ/fastmcp that referenced this pull request Mar 2, 2026
FastMCP vendored a minimal DI engine extracted from Docket (~164 lines)
with try/except fallback patterns everywhere. The `uncalled-for` package
is a clean, typed extraction of this same system, and since Docket will
also depend on it (chrisguidry/docket#353), `uncalled_for.Dependency`
becomes the single canonical base class.

This deletes the `_vendor/docket_di/` directory, replaces all the
try/except import patterns with direct `uncalled_for` imports, and
updates the `Dependency.execution` → `current_execution` ContextVar
references to match the Docket branch. The `Progress` class now
delegates to an internal impl and returns `self` from `__aenter__`
(matching Docket's pattern) so that ty's generic resolution works
without `type: ignore` suppressions.

Temporarily points pydocket at the `use-uncalled-for` branch so both
sides can be validated together in CI.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
chrisguidry added a commit to PrefectHQ/fastmcp that referenced this pull request Mar 2, 2026
* Replace vendored DI with uncalled-for

FastMCP vendored a minimal DI engine extracted from Docket (~164 lines)
with try/except fallback patterns everywhere. The `uncalled-for` package
is a clean, typed extraction of this same system, and since Docket will
also depend on it (chrisguidry/docket#353), `uncalled_for.Dependency`
becomes the single canonical base class.

This deletes the `_vendor/docket_di/` directory, replaces all the
try/except import patterns with direct `uncalled_for` imports, and
updates the `Dependency.execution` → `current_execution` ContextVar
references to match the Docket branch. The `Progress` class now
delegates to an internal impl and returns `self` from `__aenter__`
(matching Docket's pattern) so that ty's generic resolution works
without `type: ignore` suppressions.

Temporarily points pydocket at the `use-uncalled-for` branch so both
sides can be validated together in CI.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Re-export Dependency from fastmcp.dependencies

Internal code like azure.py should import from the fastmcp namespace
rather than reaching into uncalled_for directly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Import Dependency from fastmcp namespace in tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add generic type parameters to Dependency subclasses

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Mention uncalled-for in DI docs

The DI engine now comes from uncalled-for, so the docs should credit
it alongside Docket. Also updates the Docket docs link to docket.lol.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Point docket dependency at main

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Bump uncalled-for pin to >=0.2.0

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix uncalled-for imports for 0.2.0 API changes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Support Shared() dependencies without docket

Enters a SharedContext at server lifetime so that Shared() dependencies
from uncalled-for resolve once and are cached across tool/resource/prompt
calls. When running with docket, the Worker already handles this; this
covers the non-docket path and direct call_tool() usage.

Also re-exports Shared from fastmcp.dependencies.

Closes #3251

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Bump docket lockfile to latest main

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Remove duplicate test classes from rebase conflict resolution

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Point docket dependency at pydocket>=0.18.0 release

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Pair SharedContext __aenter__ with __aexit__ in Context lifecycle

The old `_ensure_shared_context` on the server called `__aenter__()` on a
lazy `SharedContext` but never `__aexit__()`, leaking the exit stack and
its resources. Moved the SharedContext management into Context's own
enter/exit so it's properly paired: when docket is available the lifespan
handles it, otherwise Context creates and cleans up a per-request one.

Updated Shared() tests to use Client (which runs the lifespan) rather
than calling server methods directly, since cross-request sharing
requires a lifespan.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Hoist SharedContext import to module level

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
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.

Spin out Docket's dependency injection system as a separate library

2 participants