From eb817604ec8929dbc72948a68e48b32c39e4126a Mon Sep 17 00:00:00 2001 From: Tenshin Higashi <92330484+tenshinhigashi@users.noreply.github.com> Date: Wed, 7 Aug 2024 16:10:16 -0400 Subject: [PATCH] Fix Lint (#5735) Signed-off-by: Tenshin Higashi --- python/ambassador/fetch/dependency.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/python/ambassador/fetch/dependency.py b/python/ambassador/fetch/dependency.py index 164685cbb8..1e0d97a4b2 100644 --- a/python/ambassador/fetch/dependency.py +++ b/python/ambassador/fetch/dependency.py @@ -13,6 +13,7 @@ Type, TypeVar, ) +from typing import cast as typecast from .k8sobject import KubernetesObject, KubernetesObjectKey @@ -181,7 +182,12 @@ class DependencyManager: injectors: Mapping[Any, DependencyInjector] def __init__(self, deps: Collection[D]) -> None: - self.deps = {dep.__class__: dep for dep in deps} + # DependencyMapping requires __contains__ and __getitem__ to be + # defined, which dicts do -- however, DependencyMapping also + # requires that the argument to those two methods be a Type[D], + # which dicts do not. MyPy doesn't like this, so we have to cast + # the dict to the correct type. + self.deps = typecast(DependencyMapping, {dep.__class__: dep for dep in deps}) self.injectors = defaultdict(lambda: DependencyInjector(self.deps)) def for_instance(self, obj: Any) -> DependencyInjector: