Use uncalled-for for dependency injection plumbing#353
Merged
chrisguidry merged 5 commits intomainfrom Feb 27, 2026
Merged
Conversation
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>
Documentation build overview
Show files changed (2 files in total): 📝 2 modified | ➕ 0 added | ➖ 0 deleted
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #353 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 99 99
Lines 3098 2969 -129
Branches 27 26 -1
==========================================
- Hits 3098 2969 -129
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
💡 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".
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>
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
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Docket's DI engine was extracted into the standalone
uncalled-forlibrary. 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.dependenciesexactly 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.pyrather than class attributes on a customDependencysubclass, soDependencyis just a direct re-export ofuncalled_for.Dependency.Net result: −394 lines, +167 lines across the dependencies package.
Closes #352
🤖 Generated with Claude Code