diff --git a/sdks/python/apache_beam/internal/__init__.py b/sdks/python/apache_beam/internal/__init__.py index 0bce5d68f724..84381ed71d4f 100644 --- a/sdks/python/apache_beam/internal/__init__.py +++ b/sdks/python/apache_beam/internal/__init__.py @@ -16,3 +16,5 @@ # """For internal use only; no backwards-compatibility guarantees.""" + +from __future__ import absolute_import diff --git a/sdks/python/apache_beam/internal/gcp/__init__.py b/sdks/python/apache_beam/internal/gcp/__init__.py index 0bce5d68f724..84381ed71d4f 100644 --- a/sdks/python/apache_beam/internal/gcp/__init__.py +++ b/sdks/python/apache_beam/internal/gcp/__init__.py @@ -16,3 +16,5 @@ # """For internal use only; no backwards-compatibility guarantees.""" + +from __future__ import absolute_import diff --git a/sdks/python/apache_beam/internal/gcp/auth.py b/sdks/python/apache_beam/internal/gcp/auth.py index 97a0ef83e85d..cff88879d1ae 100644 --- a/sdks/python/apache_beam/internal/gcp/auth.py +++ b/sdks/python/apache_beam/internal/gcp/auth.py @@ -17,17 +17,19 @@ """Dataflow credentials and authentication.""" +from __future__ import absolute_import + import datetime import json import logging import os +from future.moves.urllib.request import Request +from future.moves.urllib.request import urlopen from oauth2client.client import GoogleCredentials from oauth2client.client import OAuth2Credentials from apache_beam.utils import retry -from six.moves.urllib.request import Request -from six.moves.urllib.request import urlopen # When we are running in GCE, we can authenticate with VM credentials. is_running_in_gce = False diff --git a/sdks/python/apache_beam/internal/gcp/json_value.py b/sdks/python/apache_beam/internal/gcp/json_value.py index c4f3d7ba4da6..a4c6fb9d135a 100644 --- a/sdks/python/apache_beam/internal/gcp/json_value.py +++ b/sdks/python/apache_beam/internal/gcp/json_value.py @@ -17,6 +17,10 @@ """JSON conversion utility functions.""" +from __future__ import absolute_import + +from apache_beam.options.value_provider import ValueProvider + # Protect against environments where apitools library is not available. # pylint: disable=wrong-import-order, wrong-import-position try: @@ -25,9 +29,12 @@ extra_types = None # pylint: enable=wrong-import-order, wrong-import-position -import six - -from apache_beam.options.value_provider import ValueProvider +try: # Python 2 + unicode # pylint: disable=unicode-builtin + long # pylint: disable=long-builtin +except NameError: # Python 3 + unicode = str + long = int _MAXINT64 = (1 << 63) - 1 _MININT64 = - (1 << 63) @@ -49,7 +56,7 @@ def get_typed_value_descriptor(obj): ~exceptions.TypeError: if the Python object has a type that is not supported. """ - if isinstance(obj, six.string_types): + if isinstance(obj, (str, unicode)): type_name = 'Text' elif isinstance(obj, bool): type_name = 'Boolean' @@ -101,11 +108,11 @@ def to_json_value(obj, with_type=False): return extra_types.JsonValue(object_value=json_object) elif with_type: return to_json_value(get_typed_value_descriptor(obj), with_type=False) - elif isinstance(obj, six.string_types): + elif isinstance(obj, (str, unicode)): return extra_types.JsonValue(string_value=obj) elif isinstance(obj, bool): return extra_types.JsonValue(boolean_value=obj) - elif isinstance(obj, six.integer_types): + elif isinstance(obj, (int, long)): if _MININT64 <= obj <= _MAXINT64: return extra_types.JsonValue(integer_value=obj) else: diff --git a/sdks/python/apache_beam/internal/gcp/json_value_test.py b/sdks/python/apache_beam/internal/gcp/json_value_test.py index c22d067beea0..e7cf7f15e361 100644 --- a/sdks/python/apache_beam/internal/gcp/json_value_test.py +++ b/sdks/python/apache_beam/internal/gcp/json_value_test.py @@ -17,6 +17,8 @@ """Unit tests for the json_value module.""" +from __future__ import absolute_import + import unittest from apache_beam.internal.gcp.json_value import from_json_value diff --git a/sdks/python/apache_beam/internal/module_test.py b/sdks/python/apache_beam/internal/module_test.py index be34ac27e25b..baed9652b695 100644 --- a/sdks/python/apache_beam/internal/module_test.py +++ b/sdks/python/apache_beam/internal/module_test.py @@ -17,7 +17,10 @@ """Module used to define functions and classes used by the coder unit tests.""" +from __future__ import absolute_import + import re +from builtins import object class TopClass(object): diff --git a/sdks/python/apache_beam/internal/pickler.py b/sdks/python/apache_beam/internal/pickler.py index 3e4fe05974be..3a04d8c36bf3 100644 --- a/sdks/python/apache_beam/internal/pickler.py +++ b/sdks/python/apache_beam/internal/pickler.py @@ -28,6 +28,8 @@ the coders.*PickleCoder classes should be used instead. """ +from __future__ import absolute_import + import base64 import logging import sys diff --git a/sdks/python/apache_beam/internal/pickler_test.py b/sdks/python/apache_beam/internal/pickler_test.py index e75dac384628..79208aa10706 100644 --- a/sdks/python/apache_beam/internal/pickler_test.py +++ b/sdks/python/apache_beam/internal/pickler_test.py @@ -17,6 +17,8 @@ """Unit tests for the pickler module.""" +from __future__ import absolute_import + import unittest from apache_beam.internal import module_test diff --git a/sdks/python/apache_beam/internal/util.py b/sdks/python/apache_beam/internal/util.py index e74dd4333ac6..afa4b0563b8d 100644 --- a/sdks/python/apache_beam/internal/util.py +++ b/sdks/python/apache_beam/internal/util.py @@ -20,9 +20,12 @@ For internal use only. No backwards compatibility guarantees. """ +from __future__ import absolute_import + import logging import threading import weakref +from builtins import object from multiprocessing.pool import ThreadPool @@ -51,6 +54,9 @@ def __eq__(self, other): """ return isinstance(other, ArgumentPlaceholder) + def __hash__(self): + return hash(type(self)) + def remove_objects_from_args(args, kwargs, pvalue_classes): """For internal use only; no backwards-compatibility guarantees. diff --git a/sdks/python/apache_beam/internal/util_test.py b/sdks/python/apache_beam/internal/util_test.py index 9a2e3977a708..aeba8dcdf444 100644 --- a/sdks/python/apache_beam/internal/util_test.py +++ b/sdks/python/apache_beam/internal/util_test.py @@ -16,6 +16,7 @@ # """Unit tests for the util module.""" +from __future__ import absolute_import import unittest diff --git a/sdks/python/tox.ini b/sdks/python/tox.ini index 61dc12c3017a..481c5f984a06 100644 --- a/sdks/python/tox.ini +++ b/sdks/python/tox.ini @@ -99,6 +99,7 @@ deps = flake8==3.5.0 modules = apache_beam/coders + apache_beam/internal apache_beam/metrics commands = python --version