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

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

                Author: ASF GitHub Bot
            Created on: 26/Feb/20 18:43
            Start Date: 26/Feb/20 18:43
    Worklog Time Spent: 10m 
      Work Description: chadrik commented on pull request #10822: [BEAM-7746] 
Minor typing updates / fixes
URL: https://github.com/apache/beam/pull/10822#discussion_r384689098
 
 

 ##########
 File path: sdks/python/apache_beam/transforms/external_java.py
 ##########
 @@ -37,18 +39,19 @@
 
 # Protect against environments where apitools library is not available.
 # pylint: disable=wrong-import-order, wrong-import-position
+apiclient = None  # type: Optional[types.ModuleType]
 
 Review comment:
   I completely agree.  Unfortunately, this is a syntax error in mypy:
   
   ```python
   try:
     from apache_beam.runners.dataflow.internal import apiclient  # type: 
Optional[types.ModuleType]
   except ImportError:
     apiclient = None
   ```
   
   As is this:
   ```python
   try:
     import apache_beam.runners.dataflow.internal.apiclient as apiclient  # 
type: Optional[types.ModuleType]
   except ImportError:
     apiclient = None
   ```
   
   The reason is that type comments are (by design) not capable of doing 
anything that the new PEP 526 variable annotations are not.  In other words, 
this is obviously wrong:
   
   ```python
   try:
     Optional[types.ModuleType]: import 
apache_beam.runners.dataflow.internal.apiclient as apiclient 
   except ImportError:
     apiclient = None
   ```
   
   In that context, this makes more sense:
   
   ```python
   apiclient: Optional[types.ModuleType] = None
   try:
     from apache_beam.runners.dataflow.internal import apiclient
   except ImportError:
     pass
   ```
   
 
----------------------------------------------------------------
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: 393685)
    Time Spent: 66h  (was: 65h 50m)

> 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: 66h
>  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