[ 
https://issues.apache.org/jira/browse/BEAM-7746?focusedWorklogId=408160&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-408160
 ]

ASF GitHub Bot logged work on BEAM-7746:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 23/Mar/20 19:07
            Start Date: 23/Mar/20 19:07
    Worklog Time Spent: 10m 
      Work Description: chadrik commented on pull request #11038: [BEAM-7746] 
More typing fixes
URL: https://github.com/apache/beam/pull/11038#discussion_r396690657
 
 

 ##########
 File path: sdks/python/apache_beam/transforms/core.py
 ##########
 @@ -1300,12 +1300,13 @@ def to_runner_api_parameter(self, context):
           common_urns.requirements.REQUIRES_STATEFUL_PROCESSING.urn)
     from apache_beam.runners.common import DoFnSignature
     sig = DoFnSignature(self.fn)
-    is_splittable = sig.is_splittable_dofn()
 
 Review comment:
   > Not sure if checking get_restriction_coder() return type instead of 
is_splittable_dofn() is future proof.
   
   `get_restriction_coder()` calls `is_splittable_dofn()` and returns `None` if 
it's not splittable.  So I interpreted a `None` result from this method to mean 
"is not splittable". 
   
   ```python
     def get_restriction_coder(self):
       # type: () -> Optional[TupleCoder]
   
       """Get coder for a restriction when processing an SDF. """
       if self.is_splittable_dofn():
         return TupleCoder([
             (self.get_restriction_provider().restriction_coder()),
             (self.get_watermark_estimator_provider().estimator_state_coder())
         ])
       else:
         return None
   ```
   
   > I don't understand the change, from a mypy correctness perspective.
   
   Here's the problem:
   
   ```python
       if is_splittable:
         restriction_coder = sig.get_restriction_coder()  #  returns 
Optional[TupleCoder]
         restriction_coder_id = context.coders.get_id(restriction_coder)  # 
does not accept Optional!
       else:
         restriction_coder_id = None
   ```
   
   With my changes, we naturally drop the optionality before passing the value 
to `context.coders.get_id()`.  We also avoid a redundant call to 
`is_splittable_dofn()`, FWIW.
   
   I see two options:
   
   1) keep my changes and update the documentation of `get_restriction_coder()` 
to clarify that `None` result indicates "is not splittable"
   2) revert my changes and add `assert restriction_coder is None` before the 
call to `context.coders.get_id()`
   
   
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 408160)
    Time Spent: 77.5h  (was: 77h 20m)

> Add type hints to python code
> -----------------------------
>
>                 Key: BEAM-7746
>                 URL: https://issues.apache.org/jira/browse/BEAM-7746
>             Project: Beam
>          Issue Type: New Feature
>          Components: sdk-py-core
>            Reporter: Chad Dombrova
>            Assignee: Chad Dombrova
>            Priority: Major
>          Time Spent: 77.5h
>  Remaining Estimate: 0h
>
> As a developer of the beam source code, I would like the code to use pep484 
> type hints so that I can clearly see what types are required, get completion 
> in my IDE, and enforce code correctness via a static analyzer like mypy.
> This may be considered a precursor to BEAM-7060
> Work has been started here:  [https://github.com/apache/beam/pull/9056]
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to