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

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

                Author: ASF GitHub Bot
            Created on: 20/Feb/19 00:47
            Start Date: 20/Feb/19 00:47
    Worklog Time Spent: 10m 
      Work Description: tvalentyn commented on pull request #7873: [BEAM-6709] 
Check tuple typing failure.
URL: https://github.com/apache/beam/pull/7873#discussion_r258291272
 
 

 ##########
 File path: sdks/python/apache_beam/typehints/native_type_compatibility.py
 ##########
 @@ -37,14 +38,33 @@
 
 def _get_arg(typ, index):
   """Returns the index-th argument to the given type."""
-  return typ.__args__[index]
+  try:
+    return typ.__args__[index]
+  except AttributeError:
+    if (3, 0, 0) <= sys.version_info[0:3] < (3, 5, 3):
+      # On Python versions < 3.5.3, the Tuple and Union type from typing do
+      # not have an __args__ attribute, but a __tuple_params__, and a
+      # __union_params__ and __union_set_params__ argument respectively.
+      args = next(value for key, value in typ.__dict__.items()
 
 Review comment:
   This looks correct, but is hard to read. I suggest, we rewrite this to be 
more explicit here:
   
   ```
   if has_attr(typ, '__tuple_params__') :
     args = typ.__tuple_params__
   elif has_attr(typ, '__union_params__'):
     args = typ.__union_params__
   else:
     assert False, "Only Union or Tuple metatypes are expected here."
   return args[index]
   ```
   We can do a similar change below.
   
   Also R: @charlesccychen to take another look on this change, thank you.
   
   FYI, 3.5.2 seems to use this revision of typing.py 
https://github.com/python/cpython/blob/3b557991d4a7626cf12baf2277bc87acbc439744/Lib/typing.py,
 changed in 
https://github.com/python/cpython/commit/5fc25a873cfdec27e46f71e62c9b65df5667c1b4#diff-015978a768b517a38abbc0ecdea87f5a.
  
   
   
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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: 201000)
    Time Spent: 50m  (was: 40m)

> Typehinting depends on typing changes in Python 3.5.3
> -----------------------------------------------------
>
>                 Key: BEAM-6709
>                 URL: https://issues.apache.org/jira/browse/BEAM-6709
>             Project: Beam
>          Issue Type: Sub-task
>          Components: sdk-py-core
>            Reporter: Robbe
>            Assignee: Robbe
>            Priority: Major
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> On Python versions < 3.5.3, the Tuple and Union type from typing do not have 
> an `__args__` attribute, but a `__tuple_params__`, and a `__union_params__` 
> and `__union_set_params__` argument respectively.
> The current implementation fails <3.5.3 since it depends on the `__args__` 
> attribute



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to