Add support for sync functions and context managers in Depends#172
Add support for sync functions and context managers in Depends#172chrisguidry merged 4 commits intomainfrom
Depends#172Conversation
Enable dependency injection for both sync and async code to simplify testing and allow integration with existing synchronous libraries. Dependencies now support: - Sync functions returning values - Sync context managers (@contextmanager) - Async functions (existing) - Async context managers (existing) All dependency types work seamlessly together with automatic detection and proper resource cleanup. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Claude finished @desertaxle's task —— View job Code Review: Add support for sync functions and context managers in
|
|
📚 Documentation has been built for this PR! You can download the documentation directly here: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #172 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 34 34
Lines 4834 5047 +213
Branches 265 267 +2
==========================================
+ Hits 4834 5047 +213
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Replace examples showing blocking operations (file I/O, locks) with non-blocking patterns: - Pure computations (config merging, param building) - In-memory operations (dict/set access) - Quick transformations Add clear guidance that sync dependencies should NEVER include blocking I/O operations. All I/O must use async dependencies. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Depends
Summary
Enables dependency injection for both synchronous and asynchronous code, making it easier to:
Important: Sync dependencies should NOT include blocking I/O. Use async dependencies for any I/O operations.
Changes
Depends()now accepts sync functions, sync context managers (@contextmanager), async functions, and async context managers (@asynccontextmanager)Examples
Sync dependency - pure computation
Async dependency - I/O operations
What NOT to do
Use Cases
Best for sync dependencies:
Use async dependencies for:
awaitTesting
test_dependencies.pycovering all sync scenariostest_fundamentals.pyto document the feature🤖 Generated with Claude Code