Skip to content

Commit

Permalink
Remove unused RequestScope
Browse files Browse the repository at this point in the history
  • Loading branch information
nick8325 committed Feb 12, 2024
1 parent c64d526 commit 1cf43b2
Showing 1 changed file with 0 additions and 44 deletions.
44 changes: 0 additions & 44 deletions karp-backend/src/karp/main/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,50 +33,6 @@
logger = logging.getLogger(__name__)


class RequestScope(injector.Scope): # noqa: D101
REGISTRY_KEY = "RequestScopeRegistry"

def configure(self) -> None: # noqa: D102
self._locals = threading.local()

def enter(self) -> None: # noqa: D102
logger.warning("entering request scope")
assert not hasattr(self._locals, self.REGISTRY_KEY) # noqa: S101
setattr(self._locals, self.REGISTRY_KEY, {})

def exit(self) -> None: # noqa: A003, D102
logger.warning("exiting request scope")
for key, provider in getattr(self._locals, self.REGISTRY_KEY).items():
provider.get(self.injector).close()
delattr(self._locals, repr(key))

delattr(self._locals, self.REGISTRY_KEY)

def __enter__(self) -> None: # noqa: D105
self.enter()

def __exit__(self, exc_type, exc_val, exc_tb) -> None: # type: ignore # noqa: D105
self.exit()

def get(self, key: Type[T], provider: Provider[T]) -> Provider[T]: # noqa: D102
try:
return getattr(self._locals, repr(key)) # type: ignore
except AttributeError:
provider = injector.InstanceProvider(provider.get(self.injector))
setattr(self._locals, repr(key), provider)
try:
registry = getattr(self._locals, self.REGISTRY_KEY)
except AttributeError:
raise Exception( # noqa: B904
f"{key} is request scoped, but no RequestScope entered!"
)
registry[key] = provider
return provider


request = injector.ScopeDecorator(RequestScope)


class CommandsMod(injector.Module): # noqa: D101
@injector.provider
def entry_commands(
Expand Down

0 comments on commit 1cf43b2

Please sign in to comment.