From 8573ff38256e5de5ca6765d8fb6b731e36b9f746 Mon Sep 17 00:00:00 2001 From: Christopher Wilcox Date: Mon, 23 Mar 2020 17:09:22 -0700 Subject: [PATCH] Modify async to async_ to avoid reserved keyword clash. (#728) * Add Python 3.7 to tox * Refactor references of async to async_ for Python 3 compatibility * add missing trove for python 3 --- datalab/utils/__init__.py | 4 ++-- datalab/utils/_async.py | 12 ++++++------ datalab/utils/_lambda_job.py | 2 +- google/datalab/utils/__init__.py | 4 ++-- google/datalab/utils/_async.py | 12 ++++++------ google/datalab/utils/_lambda_job.py | 2 +- setup.py | 1 + tox.ini | 6 +++--- 8 files changed, 22 insertions(+), 21 deletions(-) diff --git a/datalab/utils/__init__.py b/datalab/utils/__init__.py index a68bad496..720a80127 100644 --- a/datalab/utils/__init__.py +++ b/datalab/utils/__init__.py @@ -12,7 +12,7 @@ """Google Cloud Platform library - Internal Helpers.""" -from ._async import async, async_function, async_method +from ._async import async_, async_function, async_method from ._gcp_job import GCPJob from ._http import Http, RequestException from ._iterator import Iterator @@ -24,7 +24,7 @@ from ._utils import print_exception_with_last_stack, get_item, compare_datetimes, \ pick_unused_port, is_http_running_on, gcs_copy_file -__all__ = ['async', 'async_function', 'async_method', 'GCPJob', 'Http', 'RequestException', +__all__ = ['async_', 'async_function', 'async_method', 'GCPJob', 'Http', 'RequestException', 'Iterator', 'Job', 'JobError', 'JSONEncoder', 'LRUCache', 'LambdaJob', 'DataflowJob', 'print_exception_with_last_stack', 'get_item', 'compare_datetimes', 'pick_unused_port', 'is_http_running_on', 'gcs_copy_file'] diff --git a/datalab/utils/_async.py b/datalab/utils/_async.py index 510b68f93..b7559f009 100644 --- a/datalab/utils/_async.py +++ b/datalab/utils/_async.py @@ -23,7 +23,7 @@ from future.utils import with_metaclass -class async(with_metaclass(abc.ABCMeta, object)): +class async_(with_metaclass(abc.ABCMeta, object)): """ Base class for async_function/async_method. Creates a wrapped function/method that will run the original function/method on a thread pool worker thread and return a Job instance for monitoring the status of the thread. @@ -55,7 +55,7 @@ def __call__(self, *args, **kwargs): return _job.Job(future=self.executor.submit(self._call, *args, **kwargs)) -class async_function(async): +class async_function(async_): """ This decorator can be applied to any static function that makes blocking calls to create a modified version that creates a Job and returns immediately; the original method will be called on a thread pool worker thread. @@ -63,10 +63,10 @@ class async_function(async): def _call(self, *args, **kwargs): # Call the wrapped method. - return self._function(*async._preprocess_args(*args), **async._preprocess_kwargs(**kwargs)) + return self._function(*async_._preprocess_args(*args), **async_._preprocess_kwargs(**kwargs)) -class async_method(async): +class async_method(async_): """ This decorator can be applied to any class instance method that makes blocking calls to create a modified version that creates a Job and returns immediately; the original method will be called on a thread pool worker thread. @@ -74,8 +74,8 @@ class async_method(async): def _call(self, *args, **kwargs): # Call the wrapped method. - return self._function(self.obj, *async._preprocess_args(*args), - **async._preprocess_kwargs(**kwargs)) + return self._function(self.obj, *async_._preprocess_args(*args), + **async_._preprocess_kwargs(**kwargs)) def __get__(self, instance, owner): # This is important for attribute inheritance and setting self.obj so it can be diff --git a/datalab/utils/_lambda_job.py b/datalab/utils/_lambda_job.py index 740cd91f7..2fed3176e 100644 --- a/datalab/utils/_lambda_job.py +++ b/datalab/utils/_lambda_job.py @@ -30,7 +30,7 @@ def __init__(self, fn, job_id, *args, **kwargs): job_id: an optional ID for the job. If None, a UUID will be generated. """ super(LambdaJob, self).__init__(job_id) - self._future = _async.async.executor.submit(fn, *args, **kwargs) + self._future = _async.async_.executor.submit(fn, *args, **kwargs) def __repr__(self): """Returns a representation for the job for showing in the notebook. diff --git a/google/datalab/utils/__init__.py b/google/datalab/utils/__init__.py index 2ce0eb479..f4780c937 100644 --- a/google/datalab/utils/__init__.py +++ b/google/datalab/utils/__init__.py @@ -12,7 +12,7 @@ """Google Cloud Platform library - Internal Helpers.""" -from ._async import async, async_function, async_method +from ._async import async_, async_function, async_method from ._http import Http, RequestException from ._iterator import Iterator from ._json_encoder import JSONEncoder @@ -23,7 +23,7 @@ pick_unused_port, is_http_running_on, gcs_copy_file, python_portable_string -__all__ = ['async', 'async_function', 'async_method', 'Http', 'RequestException', 'Iterator', +__all__ = ['async_', 'async_function', 'async_method', 'Http', 'RequestException', 'Iterator', 'JSONEncoder', 'LRUCache', 'LambdaJob', 'DataflowJob', 'print_exception_with_last_stack', 'get_item', 'compare_datetimes', 'pick_unused_port', 'is_http_running_on', 'gcs_copy_file', 'python_portable_string'] diff --git a/google/datalab/utils/_async.py b/google/datalab/utils/_async.py index 60aa23e1e..b22db85d0 100644 --- a/google/datalab/utils/_async.py +++ b/google/datalab/utils/_async.py @@ -23,7 +23,7 @@ from future.utils import with_metaclass -class async(with_metaclass(abc.ABCMeta, object)): +class async_(with_metaclass(abc.ABCMeta, object)): """ Base class for async_function/async_method. Creates a wrapped function/method that will run the original function/method on a thread pool worker thread and return a Job instance for monitoring the status of the thread. @@ -55,7 +55,7 @@ def __call__(self, *args, **kwargs): return Job(future=self.executor.submit(self._call, *args, **kwargs)) -class async_function(async): +class async_function(async_): """ This decorator can be applied to any static function that makes blocking calls to create a modified version that creates a Job and returns immediately; the original method will be called on a thread pool worker thread. @@ -63,10 +63,10 @@ class async_function(async): def _call(self, *args, **kwargs): # Call the wrapped method. - return self._function(*async._preprocess_args(*args), **async._preprocess_kwargs(**kwargs)) + return self._function(*async_._preprocess_args(*args), **async_._preprocess_kwargs(**kwargs)) -class async_method(async): +class async_method(async_): """ This decorator can be applied to any class instance method that makes blocking calls to create a modified version that creates a Job and returns immediately; the original method will be called on a thread pool worker thread. @@ -74,8 +74,8 @@ class async_method(async): def _call(self, *args, **kwargs): # Call the wrapped method. - return self._function(self.obj, *async._preprocess_args(*args), - **async._preprocess_kwargs(**kwargs)) + return self._function(self.obj, *async_._preprocess_args(*args), + **async_._preprocess_kwargs(**kwargs)) def __get__(self, instance, owner): # This is important for attribute inheritance and setting self.obj so it can be diff --git a/google/datalab/utils/_lambda_job.py b/google/datalab/utils/_lambda_job.py index 74116d73d..2faa4e5ed 100644 --- a/google/datalab/utils/_lambda_job.py +++ b/google/datalab/utils/_lambda_job.py @@ -30,7 +30,7 @@ def __init__(self, fn, job_id, *args, **kwargs): job_id: an optional ID for the job. If None, a UUID will be generated. """ super(LambdaJob, self).__init__(job_id) - self._future = _async.async.executor.submit(fn, *args, **kwargs) + self._future = _async.async_.executor.submit(fn, *args, **kwargs) def __repr__(self): """Returns a representation for the job for showing in the notebook. diff --git a/setup.py b/setup.py index 8c524f7d7..6ad55fcb9 100644 --- a/setup.py +++ b/setup.py @@ -78,6 +78,7 @@ classifiers=[ "Programming Language :: Python", "Programming Language :: Python :: 2", + "Programming Language :: Python :: 3", "Development Status :: 4 - Beta", "Environment :: Other Environment", "Intended Audience :: Developers", diff --git a/tox.ini b/tox.ini index 99379028e..8b7c092fa 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] -# By default, we want to run tests for Python 2.7, Python 3.5, and run our -# flake8 checks. -envlist = py27,py35,flake8,coveralls +# By default, we want to run tests for Python 2.7, Python 3.5, Python 3.7, +# and run our flake8 checks. +envlist = py27,py35,py37,flake8,coveralls # If an interpreter is missing locally, skip it. skip_missing_interpreters = true