[
https://issues.apache.org/jira/browse/BEAM-5322?focusedWorklogId=150912&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-150912
]
ASF GitHub Bot logged work on BEAM-5322:
----------------------------------------
Author: ASF GitHub Bot
Created on: 03/Oct/18 19:44
Start Date: 03/Oct/18 19:44
Worklog Time Spent: 10m
Work Description: aaltay closed pull request #6541: [BEAM-5322] Partially
port typehints
URL: https://github.com/apache/beam/pull/6541
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/sdks/python/apache_beam/typehints/native_type_compatibility_test.py
b/sdks/python/apache_beam/typehints/native_type_compatibility_test.py
index 2abde69a95f..907ce98ec97 100644
--- a/sdks/python/apache_beam/typehints/native_type_compatibility_test.py
+++ b/sdks/python/apache_beam/typehints/native_type_compatibility_test.py
@@ -19,6 +19,7 @@
from __future__ import absolute_import
+import sys
import typing
import unittest
@@ -36,7 +37,8 @@ class _TestClass(object):
class NativeTypeCompatibilityTest(unittest.TestCase):
-
+ @unittest.skipIf(sys.version_info[0] == 3, 'This test still needs to be '
+ 'fixed on Python 3')
def test_convert_to_beam_type(self):
test_cases = [
('raw bytes', bytes, bytes),
@@ -78,6 +80,8 @@ def test_convert_to_beam_type(self):
native_type_compatibility.convert_to_beam_type(typing_type),
beam_type, description)
+ @unittest.skipIf(sys.version_info[0] == 3, 'This test still needs to be '
+ 'fixed on Python 3')
def test_convert_to_beam_types(self):
typing_types = [bytes, typing.List[bytes],
typing.List[typing.Tuple[bytes, int]],
diff --git a/sdks/python/apache_beam/typehints/trivial_inference_test.py
b/sdks/python/apache_beam/typehints/trivial_inference_test.py
index 9ce78fe4e5c..1c6ebd64af6 100644
--- a/sdks/python/apache_beam/typehints/trivial_inference_test.py
+++ b/sdks/python/apache_beam/typehints/trivial_inference_test.py
@@ -19,6 +19,7 @@
from __future__ import absolute_import
+import sys
import unittest
from apache_beam.typehints import trivial_inference
@@ -106,6 +107,8 @@ def testListComprehension(self):
lambda xs: [x for x in xs],
[typehints.Tuple[int, ...]])
+ @unittest.skipIf(sys.version_info[0] == 3, 'This test still needs to be '
+ 'fixed on Python 3')
def testTupleListComprehension(self):
self.assertReturnType(
typehints.List[int],
diff --git a/sdks/python/apache_beam/typehints/typed_pipeline_test.py
b/sdks/python/apache_beam/typehints/typed_pipeline_test.py
index feee4862303..fa98075fe26 100644
--- a/sdks/python/apache_beam/typehints/typed_pipeline_test.py
+++ b/sdks/python/apache_beam/typehints/typed_pipeline_test.py
@@ -20,6 +20,7 @@
from __future__ import absolute_import
import inspect
+import sys
import typing
import unittest
@@ -46,6 +47,8 @@ def repeat(s, times):
with self.assertRaises(typehints.TypeCheckError):
[1, 2, 3] | beam.Map(repeat, 3)
+ @unittest.skipIf(sys.version_info[0] == 3, 'This test still needs to be '
+ 'fixed on Python 3')
def test_non_function(self):
result = ['a', 'bb', 'c'] | beam.Map(str.upper)
self.assertEqual(['A', 'BB', 'C'], sorted(result))
@@ -102,6 +105,8 @@ def process(self, element):
[1, 2, 3] | (beam.ParDo(my_do_fn) | 'again' >> beam.ParDo(my_do_fn))
[email protected](sys.version_info[0] == 3, 'This test still needs to be '
+ 'fixed on Python 3')
class NativeTypesTest(unittest.TestCase):
def test_good_main_input(self):
@@ -196,6 +201,8 @@ def repeat(s, *times):
# with self.assertRaises(typehints.TypeCheckError):
# ['a', 'bb', 'c'] | beam.Map(repeat, 'z')
+ @unittest.skipIf(sys.version_info[0] == 3, 'This test still needs to be '
+ 'fixed on Python 3')
def test_deferred_side_inputs(self):
@typehints.with_input_types(str, int)
def repeat(s, times):
@@ -210,6 +217,8 @@ def repeat(s, times):
with self.assertRaises(typehints.TypeCheckError):
main_input | 'bis' >> beam.Map(repeat,
pvalue.AsSingleton(bad_side_input))
+ @unittest.skipIf(sys.version_info[0] == 3, 'This test still needs to be '
+ 'fixed on Python 3')
def test_deferred_side_input_iterable(self):
@typehints.with_input_types(str, typehints.Iterable[str])
def concat(glue, items):
diff --git a/sdks/python/apache_beam/typehints/typehints_test.py
b/sdks/python/apache_beam/typehints/typehints_test.py
index 53cdece0ce4..e1106cea0d9 100644
--- a/sdks/python/apache_beam/typehints/typehints_test.py
+++ b/sdks/python/apache_beam/typehints/typehints_test.py
@@ -476,8 +476,8 @@ def test_getitem_param_must_have_length_2(self):
typehints.KV[int, str, bool]
self.assertEqual("Length of parameters to a KV type-hint must be "
- "exactly 2. Passed parameters: (<type 'int'>, <type "
- "'str'>, <type 'bool'>), have a length of 3.",
+ "exactly 2. Passed parameters: ({}, {}, {}), have a "
+ "length of 3.".format(int, str, bool),
e.exception.args[0])
def test_getitem_proxy_to_tuple(self):
@@ -505,8 +505,8 @@ def test_getitem_param_must_have_length_2(self):
typehints.Dict[float, int, bool]
self.assertEqual("Length of parameters to a Dict type-hint must be "
- "exactly 2. Passed parameters: (<type 'float'>, <type "
- "'int'>, <type 'bool'>), have a length of 3.",
+ "exactly 2. Passed parameters: ({}, {}, {}), have a "
+ "length of 3.".format(float, int, bool),
e.exception.args[0])
def test_key_type_must_be_valid_composite_param(self):
@@ -591,8 +591,8 @@ def test_getitem_invalid_composite_type_param(self):
with self.assertRaises(TypeError) as e:
typehints.Set[list]
self.assertEqual("Parameter to a Set hint must be a non-sequence, a "
- "type, or a TypeConstraint. <type 'list'> is an "
- "instance of type.",
+ "type, or a TypeConstraint. {} is an instance of "
+ "type.".format(list),
e.exception.args[0])
def test_compatibility(self):
@@ -810,8 +810,8 @@ def foo(a):
m = 'a'
foo(m)
self.assertEqual("Type-hint for argument: 'a' violated. Expected an "
- "instance of <type 'int'>, instead found an "
- "instance of <type 'str'>.",
+ "instance of {}, instead found an instance of "
+ "{}.".format(int, type(m)),
e.exception.args[0])
def test_composite_type_assertion(self):
@@ -861,11 +861,12 @@ def sub(a, b):
return a - b
with self.assertRaises(TypeCheckError) as e:
- sub(1, 'two')
+ m = 'two'
+ sub(1, m)
self.assertEqual("Type-hint for argument: 'b' violated. Expected an "
- "instance of <type 'int'>, instead found an instance "
- "of <type 'str'>.",
+ "instance of {}, instead found an instance of "
+ "{}.".format(int, type(m)),
e.exception.args[0])
def test_valid_only_positional_arguments(self):
@@ -907,11 +908,12 @@ def test_type_check_violation(self):
def foo(a):
return 'test'
with self.assertRaises(TypeCheckError) as e:
- foo(4)
+ m = 4
+ foo(m)
self.assertEqual("Type-hint for return type violated. Expected an "
- "instance of <type 'int'>, instead found an instance "
- "of <type 'str'>.",
+ "instance of {}, instead found an instance of "
+ "{}.".format(int, type('test')),
e.exception.args[0])
def test_type_check_simple_type(self):
diff --git a/sdks/python/tox.ini b/sdks/python/tox.ini
index 46d2373c289..bf9175f972b 100644
--- a/sdks/python/tox.ini
+++ b/sdks/python/tox.ini
@@ -57,7 +57,7 @@ commands =
setenv =
BEAM_EXPERIMENTAL_PY3=1
modules =
-
apache_beam.coders,apache_beam.options,apache_beam.tools,apache_beam.utils,apache_beam.internal,apache_beam.metrics,apache_beam.portability,apache_beam.pipeline_test,apache_beam.pvalue_test,apache_beam.runners
+
apache_beam.typehints,apache_beam.coders,apache_beam.options,apache_beam.tools,apache_beam.utils,apache_beam.internal,apache_beam.metrics,apache_beam.portability,apache_beam.pipeline_test,apache_beam.pvalue_test,apache_beam.runners
commands =
python --version
pip --version
----------------------------------------------------------------
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: 150912)
Time Spent: 1h 10m (was: 1h)
> Finish Python 3 porting for typehints module
> --------------------------------------------
>
> Key: BEAM-5322
> URL: https://issues.apache.org/jira/browse/BEAM-5322
> Project: Beam
> Issue Type: Sub-task
> Components: sdk-py-core
> Reporter: Robbe
> Assignee: Simon
> Priority: Major
> Time Spent: 1h 10m
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)