Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made @inject more debugger friendly #122

Merged
merged 2 commits into from
May 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/asphalt/core/_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,8 +940,7 @@ def resolve_forward_refs() -> None:
del local_names
forward_refs_resolved = True

@wraps(func)
def sync_wrapper(*args: P.args, **kwargs: P.kwargs) -> Any:
def resolve_resources() -> dict[str, Any]:
if not forward_refs_resolved:
resolve_forward_refs()

Expand All @@ -957,10 +956,14 @@ def sync_wrapper(*args: P.args, **kwargs: P.kwargs) -> Any:
dependency.cls, dependency.name
)

return func(*args, **kwargs, **resources)
return resources

@wraps(func)
async def async_wrapper(*args: P.args, **kwargs: P.kwargs) -> Any:
def sync_wrapper(*args: P.args, **kwargs: P.kwargs) -> Any:
__tracebackhide__ = True
return func(*args, **kwargs, **resolve_resources())

async def resolve_resources_async() -> dict[str, Any]:
if not forward_refs_resolved:
resolve_forward_refs()

Expand All @@ -976,7 +979,12 @@ async def async_wrapper(*args: P.args, **kwargs: P.kwargs) -> Any:
dependency.cls, dependency.name
)

return await func(*args, **kwargs, **resources)
return resources

@wraps(func)
async def async_wrapper(*args: P.args, **kwargs: P.kwargs) -> Any:
__tracebackhide__ = True
return await func(*args, **kwargs, **await resolve_resources_async())

sig = signature(func)
injected_resources: dict[str, _Dependency] = {}
Expand Down
Loading