Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions faust/models/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import (
Any,
Callable,
Hashable,
Iterable,
Mapping,
Optional,
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
5 changes: 4 additions & 1 deletion faust/models/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Callable,
Dict,
FrozenSet,
Hashable,
List,
Mapping,
MutableMapping,
Expand Down Expand Up @@ -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(
Expand Down