You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "ssjhv (via GitHub)" <gi...@apache.org> on 2023/03/16 20:14:22 UTC

[GitHub] [beam] ssjhv commented on issue #23366: [Bug]: Python Runtime Type Introspection Mishandles PEP 585 Generics

ssjhv commented on issue #23366:
URL: https://github.com/apache/beam/issues/23366#issuecomment-1472675930

   Is PEP-585 supposed to be fully handled now? I noticed that imports from `collections.abc` raised typehint errors.
   
   Example:
   ```python
   from collections.abc import Iterator
   import apache_beam as beam
   
   def add_range(n: int) -> Iterator[int]:
     for i in range(n):
       yield i
   
   with beam.Pipeline() as p:
       numbers = p | "Create" >> beam.Create([1, 2, 3, 4, 5])
       numbers = numbers | beam.FlatMap(add_range)
       _ = numbers | beam.combiners.Count.PerElement() | beam.Map(print
   ```
   
   ```
   ---------------------------------------------------------------------------
   ValueError                                Traceback (most recent call last)
   /usr/local/lib/python3.9/dist-packages/apache_beam/transforms/core.py in default_type_hints(self)
       959     try:
   --> 960       type_hints = type_hints.strip_iterable()
       961     except ValueError as e:
   
   9 frames
   ValueError: collections.abc.Iterator[int] is not iterable
   
   During handling of the above exception, another exception occurred:
   
   TypeCheckError                            Traceback (most recent call last)
   /usr/local/lib/python3.9/dist-packages/apache_beam/transforms/core.py in default_type_hints(self)
       960       type_hints = type_hints.strip_iterable()
       961     except ValueError as e:
   --> 962       raise TypeCheckError(
       963           'Return value not iterable: %s: %s' %
       964           (self.display_data()['fn'].value, e))
   
   TypeCheckError: Return value not iterable: add_range: collections.abc.Iterator[int] is not iterable
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org