apache / beam

Apache Beam is a unified programming model for Batch and Streaming data processing.
https://beam.apache.org/
Apache License 2.0
7.81k stars 4.23k forks source link

[Improvement]: accept collections.abc.Iterable[T] as a type hint #24052

Open ronshapiro opened 1 year ago

ronshapiro commented 1 year ago

What happened?

Trying to use typing.Iterable[T] in Beam code works fine, but collections.abc.Iterable[T] does not.

I imagine that the special casing of the typing module should be extended to collections.abc as well.

print(typehints.is_consistent_with(Iterable[str], Iterable[Any]))
> True
print(typehints.is_consistent_with(collections.abc.Iterable[str], Iterable[Any]))
> False
print(typehints.is_consistent_with(collections.abc.Iterable[str], collections.abc.Iterable[Any]))
> TypeError: issubclass() argument 2 cannot be a parameterized generic

Issue Priority

Priority: 2

Issue Component

Component: sdk-py-core

kennknowles commented 1 year ago

CC @tvalentyn @robertwb

davidcavazos commented 1 year ago

As part of PEP-585, Python is now standardizing all type hinting annotations into the collections library rather than the typing library, starting from Python 3.9. Here's a list of all the standard generic types.

Workaround:

from __future__ import annotations