diff --git a/faust/models/fields.py b/faust/models/fields.py index c57fa0be8..a3153ad53 100644 --- a/faust/models/fields.py +++ b/faust/models/fields.py @@ -7,6 +7,7 @@ from typing import ( Any, Callable, + Hashable, Iterable, Mapping, Optional, @@ -544,7 +545,10 @@ def prepare_value(self, value: Any, *, @lru_cache(maxsize=2048) def field_for_type( - typ: Type) -> Tuple[Type[FieldDescriptorT], Optional[Type[Tag]]]: + htyp: Hashable) -> Tuple[Type[FieldDescriptorT], Optional[Type[Tag]]]: + # This is a way to make mypy >= 0.790 happy, as lru_cache + # expects a Hashable + typ = cast(Type, htyp) try: # 1) Check if type is in fast index. return TYPE_TO_FIELD[typ], None @@ -557,7 +561,8 @@ def field_for_type( else: try: if origin is not None and issubclass(origin, Tag): - return field_for_type(typ.__args__[0])[0], typ + return field_for_type( + cast(Hashable, typ.__args__[0]))[0], typ except TypeError: pass diff --git a/faust/models/record.py b/faust/models/record.py index ca1d26bc9..dd5981f7c 100644 --- a/faust/models/record.py +++ b/faust/models/record.py @@ -7,6 +7,7 @@ Callable, Dict, FrozenSet, + Hashable, List, Mapping, MutableMapping, @@ -253,7 +254,9 @@ def add_related_to_tagged_indices(field: str, else: target_type = typ if descr is None or not isinstance(descr, FieldDescriptorT): - DescriptorType, tag = field_for_type(target_type) + # Make mypy happy + hashed_target_type = cast(Hashable, target_type) + DescriptorType, tag = field_for_type(hashed_target_type) if tag: add_to_tagged_indices(field, tag) descr = DescriptorType(