Skip to content

Commit

Permalink
move file to correct location
Browse files Browse the repository at this point in the history
  • Loading branch information
meadsteve committed Nov 28, 2021
1 parent 2b52211 commit 28930f0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
24 changes: 21 additions & 3 deletions context_based.py → lagom/context_based.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import logging
from contextlib import ExitStack
from typing import Collection, Union, Type, TypeVar, Optional, cast, ContextManager, Iterator, Generator
from typing import (
Collection,
Union,
Type,
TypeVar,
Optional,
cast,
ContextManager,
Iterator,
Generator,
)

from lagom import Container
from lagom.definitions import ConstructionWithContainer, SingletonWrapper
Expand All @@ -13,7 +23,13 @@
class ContextContainer(Container):
exit_stack: Optional[ExitStack] = None

def __init__(self, container: Container, context_types: Collection[Type], context_singletons: Collection[Type] = tuple(), log_undefined_deps: Union[bool, logging.Logger] = False):
def __init__(
self,
container: Container,
context_types: Collection[Type],
context_singletons: Collection[Type] = tuple(),
log_undefined_deps: Union[bool, logging.Logger] = False,
):
super().__init__(container, log_undefined_deps)
for dep_type in set(context_types):
self[dep_type] = self._context_type_def(dep_type)
Expand All @@ -33,7 +49,9 @@ def __exit__(self, exc_type, exc_val, exc_tb):
def _context_type_def(self, dep_type: Type):
type_def = self.get_definition(Iterator[dep_type]) or self.get_definition(Generator[dep_type, None, None]) # type: ignore
if type_def is None:
raise InvalidDependencyDefinition(f"Either Iterator[{dep_type}] or Generator[{dep_type}, None, None] should be defined")
raise InvalidDependencyDefinition(
f"Either Iterator[{dep_type}] or Generator[{dep_type}, None, None] should be defined"
)
return ConstructionWithContainer(lambda c: self._context_resolver(c, type_def)) # type: ignore

def _singleton_type_def(self, dep_type: Type):
Expand Down
2 changes: 1 addition & 1 deletion lagom/integrations/fast_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from fastapi import Depends
from starlette.requests import Request

from context_based import ContextContainer
from ..context_based import ContextContainer
from ..definitions import PlainInstance
from ..interfaces import ExtendableContainer, ReadableContainer, WriteableContainer
from ..updaters import update_container_singletons
Expand Down
2 changes: 1 addition & 1 deletion tests/test_context_based_executions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import pytest

from context_based import ContextContainer
from lagom import Container, dependency_definition
from lagom.context_based import ContextContainer
from lagom.exceptions import InvalidDependencyDefinition


Expand Down

0 comments on commit 28930f0

Please sign in to comment.