aaronsarna commented on issue #24704:
URL: https://github.com/apache/beam/issues/24704#issuecomment-1647981271

   The value of TypedDict over Mapping is if the different keys are expected to 
have different values. For example, let's say I did the following:
   ```
    to_group = {
     'ints': pcoll1,  # PCollection of (str, int)
     'strs': pcoll2,  # PCollection of (str, str)
   }
   grouped = to_group | beam.CoGroupByKey()
   something = grouped | beam.MapTuple(map_grouped)
   ```
   
   If using Mapping, the method would have to start:
   ```
   def map_grouped(key: str, values: Mapping[str, Iterable[str | int]]):
     ints = values['ints']  # type: Iterable[int]
     strs = values['strs']  # type: Iterable[str]
     ...
   ```
   since the type checker can't tell which key corresponds with which value 
type.
   
   If I could instead have a TypedDict, it could be a bit cleaner:
   ```
   class GroupedValues(TypedDict):
     ints: Iterable[int]
     strs: Iterable[str]
   
   def map_grouped(key: str, values: GroupedValues):
     ints = values['ints']
     strs = values['strs']
   ```
   and the type checker needs no additional help.


-- 
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]

Reply via email to