From b316a917da7ec45bed1cf0406726fbdcba2f09f1 Mon Sep 17 00:00:00 2001 From: Matthias Feys Date: Wed, 16 May 2018 20:38:48 +0200 Subject: [PATCH 1/2] Futurize unpackaged files --- sdks/python/apache_beam/__init__.py | 2 ++ sdks/python/apache_beam/error.py | 2 ++ sdks/python/apache_beam/pipeline.py | 7 +++++-- sdks/python/apache_beam/pipeline_test.py | 4 ++++ sdks/python/apache_beam/pvalue.py | 11 ++++++++--- sdks/python/apache_beam/pvalue_test.py | 2 ++ sdks/python/tox.ini | 5 +++++ 7 files changed, 28 insertions(+), 5 deletions(-) diff --git a/sdks/python/apache_beam/__init__.py b/sdks/python/apache_beam/__init__.py index 791ebb7a342e..8bb1a53d9d03 100644 --- a/sdks/python/apache_beam/__init__.py +++ b/sdks/python/apache_beam/__init__.py @@ -72,6 +72,8 @@ """ +from __future__ import absolute_import + import sys diff --git a/sdks/python/apache_beam/error.py b/sdks/python/apache_beam/error.py index 6ecb74fb9eef..47fec08b0a7a 100644 --- a/sdks/python/apache_beam/error.py +++ b/sdks/python/apache_beam/error.py @@ -17,6 +17,8 @@ """Python Dataflow error classes.""" +from __future__ import absolute_import + class BeamError(Exception): """Base class for all Beam errors.""" diff --git a/sdks/python/apache_beam/pipeline.py b/sdks/python/apache_beam/pipeline.py index 6abc3def9854..482afa680fc0 100644 --- a/sdks/python/apache_beam/pipeline.py +++ b/sdks/python/apache_beam/pipeline.py @@ -52,6 +52,10 @@ import os import shutil import tempfile +from builtins import object +from builtins import zip + +from future.utils import with_metaclass from apache_beam import pvalue from apache_beam.internal import pickler @@ -880,7 +884,7 @@ def is_side_input(tag): return result -class PTransformOverride(object): +class PTransformOverride(with_metaclass(abc.ABCMeta, object)): """For internal use only; no backwards-compatibility guarantees. Gives a matcher and replacements for matching PTransforms. @@ -888,7 +892,6 @@ class PTransformOverride(object): TODO: Update this to support cases where input and/our output types are different. """ - __metaclass__ = abc.ABCMeta @abc.abstractmethod def matches(self, applied_ptransform): diff --git a/sdks/python/apache_beam/pipeline_test.py b/sdks/python/apache_beam/pipeline_test.py index ed27aa7658be..d8706651bb27 100644 --- a/sdks/python/apache_beam/pipeline_test.py +++ b/sdks/python/apache_beam/pipeline_test.py @@ -17,10 +17,14 @@ """Unit tests for the Pipeline class.""" +from __future__ import absolute_import + import copy import logging import platform import unittest +from builtins import object +from builtins import range from collections import defaultdict import mock diff --git a/sdks/python/apache_beam/pvalue.py b/sdks/python/apache_beam/pvalue.py index 00597525763a..739f0b6c550d 100644 --- a/sdks/python/apache_beam/pvalue.py +++ b/sdks/python/apache_beam/pvalue.py @@ -28,8 +28,8 @@ import collections import itertools - -from six import string_types +from builtins import hex +from builtins import object from apache_beam import coders from apache_beam import typehints @@ -38,6 +38,11 @@ from apache_beam.portability import python_urns from apache_beam.portability.api import beam_runner_api_pb2 +try: + unicode # pylint: disable=unicode-builtin +except NameError: + unicode = str + __all__ = [ 'PCollection', 'TaggedOutput', @@ -261,7 +266,7 @@ class TaggedOutput(object): """ def __init__(self, tag, value): - if not isinstance(tag, string_types): + if not isinstance(tag, (bytes, unicode)): raise TypeError( 'Attempting to create a TaggedOutput with non-string tag %s' % tag) self.tag = tag diff --git a/sdks/python/apache_beam/pvalue_test.py b/sdks/python/apache_beam/pvalue_test.py index 48203df62595..b01902a42e1d 100644 --- a/sdks/python/apache_beam/pvalue_test.py +++ b/sdks/python/apache_beam/pvalue_test.py @@ -17,6 +17,8 @@ """Unit tests for the PValue and PCollection classes.""" +from __future__ import absolute_import + import unittest from apache_beam.pvalue import AsSingleton diff --git a/sdks/python/tox.ini b/sdks/python/tox.ini index caa899de2dbe..e6afd18eebe1 100644 --- a/sdks/python/tox.ini +++ b/sdks/python/tox.ini @@ -99,6 +99,11 @@ deps = flake8==3.5.0 modules = apache_beam/coders + apache_beam/error + apache_beam/pipeline + apache_beam/pipeline_test + apache_beam/pvalue + apache_beam/pvalue_test commands = python --version pip --version From f856d41c23300d382eebbae67fc9881ef7e2c36a Mon Sep 17 00:00:00 2001 From: Matthias Feys Date: Wed, 16 May 2018 23:49:38 +0200 Subject: [PATCH 2/2] resolved six.string_types equivalency --- sdks/python/apache_beam/pvalue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdks/python/apache_beam/pvalue.py b/sdks/python/apache_beam/pvalue.py index 739f0b6c550d..8285146561d8 100644 --- a/sdks/python/apache_beam/pvalue.py +++ b/sdks/python/apache_beam/pvalue.py @@ -266,7 +266,7 @@ class TaggedOutput(object): """ def __init__(self, tag, value): - if not isinstance(tag, (bytes, unicode)): + if not isinstance(tag, (str, unicode)): raise TypeError( 'Attempting to create a TaggedOutput with non-string tag %s' % tag) self.tag = tag