You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "hjtran (via GitHub)" <gi...@apache.org> on 2025/04/24 12:58:43 UTC
[I] [Bug]: [Python SDK] Beam.FlatMap doesn't correctly parse TypeVar typehints [beam]
hjtran opened a new issue, #34732:
URL: https://github.com/apache/beam/issues/34732
### What happened?
If you use a TypeVar for type hints in the callable passed to FlatMap, it sometimes will not infer the correct output type hint. Example:
```python
@typehints.with_input_types(str)
class FooTransform(beam.PTransform):
def expand(self, pcoll):
return pcoll
T = typing.TypeVar('T')
def list_str_identity(s: T) -> T:
return s
with beam.Pipeline() as p:
(p | beam.Create([['hello world']])
| beam.FlatMap(list_str_identity)
| FooTransform()
| beam.LogElements())
```
This should log "hello world", but instead results in the following error:
```
utput: Traceback (most recent call last):
File "/opt/playground/backend/executable_files/99dcf1c5-5131-46fe-b66a-f572a0d45ded/99dcf1c5-5131-46fe-b66a-f572a0d45ded.py", line 44, in <module>
(p | beam.Create([['hello world']])
File "/usr/local/lib/python3.10/site-packages/apache_beam/pvalue.py", line 138, in __or__
return self.pipeline.apply(ptransform, self)
File "/usr/local/lib/python3.10/site-packages/apache_beam/pipeline.py", line 781, in apply
transform.type_check_inputs(pvalueish)
File "/usr/local/lib/python3.10/site-packages/apache_beam/transforms/ptransform.py", line 465, in type_check_inputs
self.type_check_inputs_or_outputs(pvalueish, 'input')
File "/usr/local/lib/python3.10/site-packages/apache_beam/transforms/ptransform.py", line 494, in type_check_inputs_or_outputs
raise TypeCheckError(
apache_beam.typehints.decorators.TypeCheckError: Input type hint violation at FooTransform: expected <class 'str'>, got List[<class 'str'>]
```
The default callable for `FlatMap` is an identity function typed with `T = TypeVar("T")`, which means this incorrect type hint comes up a lot
### Issue Priority
Priority: 2 (default / most bugs should be filed as P2)
### Issue Components
- [ ] Component: Python SDK
- [ ] Component: Java SDK
- [ ] Component: Go SDK
- [ ] Component: Typescript SDK
- [ ] Component: IO connector
- [ ] Component: Beam YAML
- [ ] Component: Beam examples
- [ ] Component: Beam playground
- [ ] Component: Beam katas
- [ ] Component: Website
- [ ] Component: Infrastructure
- [ ] Component: Spark Runner
- [ ] Component: Flink Runner
- [ ] Component: Samza Runner
- [ ] Component: Twister2 Runner
- [ ] Component: Hazelcast Jet Runner
- [ ] Component: Google Cloud Dataflow Runner
--
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.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug]: [Python SDK] Beam.FlatMap doesn't correctly parse TypeVar typehints [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #34732:
URL: https://github.com/apache/beam/issues/34732#issuecomment-3318797560
This issue has been marked as stale due to 150 days of inactivity. It will be closed in 30 days if no further activity occurs. If you think that’s incorrect or this issue still needs to be addressed, please simply write any comment. If closed, you can reopen the issue at any time. Thank you for your contributions.
--
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
Re: [I] [Bug]: [Python SDK] Beam.FlatMap doesn't correctly parse TypeVar typehints [beam]
Posted by "hjtran (via GitHub)" <gi...@apache.org>.
hjtran commented on issue #34732:
URL: https://github.com/apache/beam/issues/34732#issuecomment-2827554108
cc @jrmccluskey
--
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
Re: [I] [Bug]: [Python SDK] Beam.FlatMap doesn't correctly parse TypeVar typehints [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed issue #34732: [Bug]: [Python SDK] Beam.FlatMap doesn't correctly parse TypeVar typehints
URL: https://github.com/apache/beam/issues/34732
--
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
Re: [I] [Bug]: [Python SDK] Beam.FlatMap doesn't correctly parse TypeVar typehints [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #34732:
URL: https://github.com/apache/beam/issues/34732#issuecomment-3432192308
This issue has been closed due to lack of activity. If you think that is incorrect, you can reopen the issue at any time.
--
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