Skip to content

fix: 🐛 @constant now works with async recipes#264

Merged
remimd merged 2 commits intodevfrom
constant
Jun 14, 2025
Merged

fix: 🐛 @constant now works with async recipes#264
remimd merged 2 commits intodevfrom
constant

Conversation

@remimd
Copy link
Copy Markdown
Member

@remimd remimd commented Jun 14, 2025

No description provided.

@remimd remimd requested a review from Copilot June 14, 2025 11:45
@remimd remimd self-assigned this Jun 14, 2025
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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]:

@remimd remimd merged commit 33aeeaf into dev Jun 14, 2025
5 checks passed
@remimd remimd deleted the constant branch June 14, 2025 11:48
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.

2 participants