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

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

                Author: ASF GitHub Bot
            Created on: 09/May/19 19:57
            Start Date: 09/May/19 19:57
    Worklog Time Spent: 10m 
      Work Description: tvalentyn commented on pull request #8453: [BEAM-6985] 
TypeHints Py3 Error: Native type compatibility tests fail on Python 3.7+ Updates
URL: https://github.com/apache/beam/pull/8453#discussion_r282637249
 
 

 ##########
 File path: sdks/python/apache_beam/typehints/native_type_compatibility_test.py
 ##########
 @@ -103,6 +98,64 @@ def test_convert_to_beam_types(self):
         native_type_compatibility.convert_to_beam_types(typing_types),
         beam_types)
 
+  def test_is_sub_class(self):
+    self.assertTrue(native_type_compatibility._safe_issubclass(
+        parent=typing.Dict,
+        derived=typing.Dict[bytes, int]))
+    self.assertFalse(native_type_compatibility._safe_issubclass(
+        parent=typing.List,
+        derived=typing.Dict[bytes, int]))
+    self.assertTrue(native_type_compatibility._safe_issubclass(
+        parent=typing.List,
+        derived=typing.List[bytes]))
+    self.assertFalse(native_type_compatibility._safe_issubclass(
+        parent=typing.List,
+        derived=typing.Dict[bytes, int]))
+    self.assertTrue(native_type_compatibility._safe_issubclass(
+        parent=typing.Set,
+        derived=typing.Set[int]))
+    self.assertFalse(native_type_compatibility._safe_issubclass(
+        parent=typing.List,
+        derived=typing.Set[float]))
+    self.assertTrue(native_type_compatibility._safe_issubclass(
+        parent=typing.Tuple,
+        derived=typing.Tuple[int]))
+    self.assertFalse(native_type_compatibility._safe_issubclass(
+        parent=typing.List,
+        derived=typing.Tuple[bytes]))
+
+  @unittest.skipIf(sys.version_info >= (2, 7, 0),
 
 Review comment:
   I looked a little closer into the code of native_type_compatibility module.
   
   The high-level goal of this change is to make sure that the correspondence 
between `typing` types and `apache_beam.typehints` types, defined by 
`convert_to_beam_type`, is established in the same way across all versions of 
Python. 
   
   `test_convert_to_beam_type` should help us ensure this. As long as this test 
has sufficient coverage, we don't need to test all the helpers.  
   
   `_is_subclass` is a helper function, and it's parent argument is one of 
typing.{Dict,List,Set}, so we can remove `_is_sublcass_order` test cases, which 
pass subscripted types, e.g. List[int].
   
   There are several interesting differences in how following expressions are 
evaluated  different Py3.6 / Py3.7 versions, and there may be more differences 
in other Python versions.
   
   ```
   type(typing.Any)
   type(typing.Dict)
   type(typing.List)
   type(typing.Set)
   type(typing.Tuple)
   type(typing.Union)
   
   type(typing.Any)
   type(typing.Dict[int])
   type(typing.List[int])
   type(typing.Set[int])
   type(typing.Tuple[int])
   type(typing.Union[int,str])
   
   typing.Dict[int].__origin__
   typing.List[int].__origin__
   typing.Set[int].__origin__
   typing.Tuple[int].__origin__
   typing.Union[int,str].__origin__
   
   typing.Any.__origin__
   typing.Dict.__origin__
   typing.List.__origin__
   typing.Set.__origin__
   typing.Tuple.__origin__
   typing.Union.__origin__
   ```
   Taking these differences into account, we need to make sure that whatever 
comparisons we are doing in `_match_same_type` and `_is_subclass` make sense, 
and we not just making a change that makes a test pass. A reader unfamiliar 
with this code should also be able to understand the details of implementation. 
   
   Looking at the evaluation of expressions above, I think we will be better 
off if we replace `_match_same_type` into separate `_match_union` and 
`_match_any` helpers.
 
----------------------------------------------------------------
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:
us...@infra.apache.org


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

    Worklog Id:     (was: 239914)
    Time Spent: 3h 50m  (was: 3h 40m)

> TypeHints Py3 Error: Native type compatibility tests fail on Python 3.7+
> ------------------------------------------------------------------------
>
>                 Key: BEAM-6985
>                 URL: https://issues.apache.org/jira/browse/BEAM-6985
>             Project: Beam
>          Issue Type: Sub-task
>          Components: sdk-py-core
>            Reporter: Robbe
>            Assignee: niklas Hansson
>            Priority: Major
>          Time Spent: 3h 50m
>  Remaining Estimate: 0h
>
> The following tests are failing:
> * test_convert_nested_to_beam_type 
> (apache_beam.typehints.native_type_compatibility_test.NativeTypeCompatibilityTest)
>  
> * test_convert_to_beam_type 
> (apache_beam.typehints.native_type_compatibility_test.NativeTypeCompatibilityTest)
>  
> * test_convert_to_beam_types 
> (apache_beam.typehints.native_type_compatibility_test.NativeTypeCompatibilityTest)
> With similar errors, where `typing.<Type> != <Type>`. eg:
> {noformat}
>  FAIL: test_convert_to_beam_type 
> (apache_beam.typehints.native_type_compatibility_test.NativeTypeCompatibilityTest)
>  ----------------------------------------------------------------------
>  Traceback (most recent call last):
>  File 
> "/home/jenkins/jenkins-slave/workspace/beam_PreCommit_Python_Commit/src/sdks/python/test-suites/tox/py37/build/srcs/sdks/python/apache_beam/typehints/native_type_compatibility_test.py",
>  line 79, in test_convert_to_beam_type
>  beam_type, description)
>  AssertionError: typing.Dict[bytes, int] != Dict[bytes, int] : simple dict
> {noformat}
>  



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

Reply via email to