From 6f5f4dac97cea9a891a9cd4880c7e6051b5a44f2 Mon Sep 17 00:00:00 2001 From: Johannes Kasimir Date: Mon, 15 Apr 2024 10:33:45 +0200 Subject: [PATCH] mypy --- src/sciline/pipeline.py | 42 +++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/sciline/pipeline.py b/src/sciline/pipeline.py index 6e0692e1..51a75e2a 100644 --- a/src/sciline/pipeline.py +++ b/src/sciline/pipeline.py @@ -543,7 +543,7 @@ def _get_provider( if provider := self._providers.get(tp): # Optimization to quickly find non-generic providers - matches = [(provider, {})] + matches: List[Tuple[Provider, Dict[TypeVar, Key]]] = [(provider, {})] else: matches = [ (provider, bound) @@ -568,28 +568,30 @@ def _get_provider( ) else: origin = get_origin(tp) - typevars_of_generic = _extract_typevars_from_generic_type(origin) - if typevars_of_generic: - explanation = [ - ''.join( - map( - str, - ( - 'Note that ', - key_name(origin[typevars_of_generic]), - ' has constraints ', + # Not sure this is necessary, but mypy complains + if isinstance(origin, type) and hasattr(origin, '__getitem__'): + typevars_of_generic = _extract_typevars_from_generic_type(origin) + if typevars_of_generic: + explanation = [ + ''.join( + map( + str, ( - { - key_name(tv): tuple( - map(key_name, tv.__constraints__) - ) - for tv in typevars_of_generic - } + 'Note that ', + key_name(origin[typevars_of_generic]), + ' has constraints ', + ( + { + key_name(tv): tuple( + map(key_name, tv.__constraints__) + ) + for tv in typevars_of_generic + } + ), ), - ), + ) ) - ) - ] + ] return handler.handle_unsatisfied_requirement(tp, *explanation), {} def _get_unique_provider(