github-actions[bot] commented on code in PR #41884:
URL: https://github.com/apache/beam/pull/41884#discussion_r4774183783
##########
sdks/python/apache_beam/transforms/stats.py:
##########
@@ -831,6 +833,23 @@ def __init__(
if self._input_batched:
setattr(self, 'add_input', self._add_inputs)
+ def default_type_hints(self):
+ t = typehints.TypeVariable('T')
+ if self._input_batched and self._spec.weighted:
+ input_type = Any
Review Comment:
**🟡 Medium**: When both `input_batched=True` and `weighted=True` are set,
setting `input_type = Any` and `output_type = typehints.List[Any]` causes
`ApproximateQuantiles.PerKey` and `ApproximateQuantiles.Globally` to lose the
element type `T` (inferring `Tuple[K, List[Any]]` / `List[Any]` instead of
`Tuple[K, List[T]]` / `List[T]`) for the documented `(elements_batch,
weights_batch)` tuple input format, and allows invalid non-batched value types
(e.g., `Tuple[str, int]`) to bypass static type checking.
Using `typehints.Union[typehints.Tuple[typehints.Iterable[t],
typehints.Iterable[float]], typehints.List[typehints.Iterable[Any]]]` with
`output_type = typehints.List[t]` preserves `T` for typed `(elements_batch,
weights_batch)` tuples while still accepting 2-element list batches (as used in
`test_batched_weighted_quantiles`) and rejecting non-batched inputs.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]