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

#98 Increase granularity of context. #135

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

alexanderlazarev0
Copy link
Collaborator

@alexanderlazarev0 alexanderlazarev0 commented Jan 8, 2025

Implements #98

Split context into:

  • global context
  • resource specific contexts (1 per ContextResource)

API changes:

All API changes only come in the form of extending current functionality via methods or optional arguments. Except for:

To set the global_context when calling container_context(), one needs to explicitly pass it as a keyword arguments.

Instead of:

initial_context = {}
async with container_context(initial_context):
    ...

Now one must use:

initial_context = {}
async with container_context(initial_context=initial_context):
    ...

This makes the new API incompatible with the current version!
-> Hence, my suggestion is to release this with 2.0

Points of discussion:

I will leave comments to be discusses in this pull request.

Still TODO:

  • Implement discussion changes.
  • Extend documentation.

Implementation notes:

@lesnik512 I did some test approaches prior to this implementation. Keeping one contextvars.ContextVar for all ContextResources and modifying the dict is not really feasible since you would need to deepcopy() the dict and its contents to the newly created context. In that case, one would need to look for a different solution from contextvars.

@alexanderlazarev0 alexanderlazarev0 marked this pull request as draft January 8, 2025 14:05
@alexanderlazarev0 alexanderlazarev0 added the enhancement New feature or request label Jan 8, 2025
@alexanderlazarev0 alexanderlazarev0 self-assigned this Jan 8, 2025
@alexanderlazarev0 alexanderlazarev0 added this to the 2.0.0 milestone Jan 8, 2025
tests/providers/test_attr_getter.py Outdated Show resolved Hide resolved
tests/providers/test_context_resources.py Show resolved Hide resolved
that_depends/container.py Show resolved Hide resolved
that_depends/meta.py Outdated Show resolved Hide resolved
that_depends/providers/context_resources.py Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants