eth-utils icon indicating copy to clipboard operation
eth-utils copied to clipboard

The `to_tuple` type decorators don't correctly handle generics for item types.

Open pipermerriam opened this issue 6 years ago • 1 comments

What was wrong?

When using to_tuple on a function which operates on a generic type, type safety is not preserved.

TVal = TypeVar('TVal')

@to_tuple
def typing_to_tuple_generic(values: Sequence[TVal]) -> Iterable[TVal]:
    yield from values

v_tuple_generic = typing_to_tuple_generic([1, 2, 3])
reveal_type(v_tuple_generic)  # error: Revealed type is 'builtins.tuple[TVal`-1]'

How can it be fixed?

???

pipermerriam avatar Apr 17 '19 16:04 pipermerriam

Not clear yet but this might be fixable using https://mypy.readthedocs.io/en/latest/extending_mypy.html#current-list-of-plugin-hooks

pipermerriam avatar Apr 18 '19 04:04 pipermerriam