Conversation
There was a problem hiding this comment.
Pull Request Overview
This pull request fixes the issue with the @constant decorator to properly support asynchronous recipes. It also updates the lazy evaluation functions to differentiate between synchronous and asynchronous usage and adds corresponding tests.
- Updated tests to verify that async recipes raise an error with get_instance and work with aget_instance.
- Modified the constant decorator to invoke alazy for async recipes.
- Refactored the lazy and Lazy implementations to support async evaluation.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/test_constant.py | Added tests for constant recipes with both sync and async functions. |
| injection/_core/module.py | Updated the constant decorator logic to choose between lazy/alazy based on function type. |
| injection/_core/common/lazy.py | Refactored lazy and added alazy functions along with changes in the Lazy class for async support. |
Comments suppressed due to low confidence (2)
injection/_core/module.py:515
- Consider adding a comment explaining the conditional selection between alazy and lazy based on whether the recipe is asynchronous. This will improve clarity for future maintainers.
recipe: Recipe[[], T] = alazy(wp) if iscoroutinefunction(wp) else lazy(wp) # type: ignore[arg-type]
injection/_core/common/lazy.py:7
- The lazy function now returns a callable rather than an Invertible instance. Ensure that all consumers of lazy are updated accordingly and that this change is reflected in the associated documentation.
def lazy[T](factory: Callable[..., T]) -> Callable[[], T]:
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.
No description provided.