From 788e449559060949355b0b531140be3b27a02c7c Mon Sep 17 00:00:00 2001 From: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com> Date: Thu, 30 Sep 2021 11:13:16 -0500 Subject: [PATCH] Remove unused code --- di/_local_scope_context.py | 2 +- di/_scope_map.py | 30 +----------------------------- di/_state.py | 2 -- di/executors.py | 2 +- 4 files changed, 3 insertions(+), 33 deletions(-) diff --git a/di/_local_scope_context.py b/di/_local_scope_context.py index 5a1817cb..e2c1d3ec 100644 --- a/di/_local_scope_context.py +++ b/di/_local_scope_context.py @@ -13,7 +13,7 @@ ) if TYPE_CHECKING: - from di._state import ContainerState + from di._state import ContainerState # pragma: no cover from di.types import FusedContextManager from di.types.scopes import Scope diff --git a/di/_scope_map.py b/di/_scope_map.py index 074914db..ba6345ed 100644 --- a/di/_scope_map.py +++ b/di/_scope_map.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Any, Dict, Generic, Hashable, List, TypeVar, Union, overload +from typing import Dict, Generic, Hashable, List, TypeVar from di.exceptions import DuplicateScopeError, UnknownScopeError from di.types.scopes import Scope @@ -10,9 +10,6 @@ VT = TypeVar("VT") -_unset: Any = object() - - class ScopeMap(Generic[KT, VT]): """Mapping-like structure to hold binds and cached values. @@ -52,34 +49,12 @@ def set(self, key: KT, value: VT, *, scope: Scope) -> None: if key in mapping: mapping.pop(key) - @overload - def pop(self, key: KT) -> VT: - ... - - @overload - def pop(self, key: KT, default: T) -> Union[VT, T]: - ... - - def pop(self, key: KT, default: T = _unset) -> Union[VT, T]: - for mapping in self.mappings.values(): - if key in mapping: - return mapping.pop(key) - if default is not _unset: - return default - raise KeyError(key) - def contains(self, key: KT) -> bool: for mapping in self.mappings.values(): if key in mapping: return True return False - def get_scope(self, key: KT) -> Scope: - for scope, mapping in self.mappings.items(): - if key in mapping: - return scope - raise KeyError(key) - def add_scope(self, scope: Scope) -> None: if scope in self.mappings: raise DuplicateScopeError(f"The scope {scope} already exists!") @@ -92,9 +67,6 @@ def pop_scope(self, scope: Scope) -> None: ) self.mappings.pop(scope) - def has_scope(self, scope: Scope) -> bool: - return scope in self.mappings - def copy(self) -> ScopeMap[KT, VT]: new = ScopeMap[KT, VT]() new.mappings = self.mappings.copy() diff --git a/di/_state.py b/di/_state.py index 1b71fea7..fbb81d1d 100644 --- a/di/_state.py +++ b/di/_state.py @@ -56,8 +56,6 @@ def bind( previous_provider = self.binds.get(dependency, None) self.binds[dependency] = provider - if self.cached_values.contains(dependency): - self.cached_values.pop(dependency) @contextmanager def unbind() -> Generator[None, None, None]: diff --git a/di/executors.py b/di/executors.py index a44e2e33..9121793a 100644 --- a/di/executors.py +++ b/di/executors.py @@ -18,7 +18,7 @@ def _all_sync(tasks: typing.List[Task]) -> bool: if isinstance(task, functools.partial): call = task.func # type: ignore else: - call = task + call = task # pragma: no cover if inspect.iscoroutinefunction(call): return False return True