Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.

Commit 8573ff3

Browse files
authored
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
1 parent 8c2df84 commit 8573ff3

File tree

8 files changed

+22
-21
lines changed

8 files changed

+22
-21
lines changed

datalab/utils/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
"""Google Cloud Platform library - Internal Helpers."""
1414

15-
from ._async import async, async_function, async_method
15+
from ._async import async_, async_function, async_method
1616
from ._gcp_job import GCPJob
1717
from ._http import Http, RequestException
1818
from ._iterator import Iterator
@@ -24,7 +24,7 @@
2424
from ._utils import print_exception_with_last_stack, get_item, compare_datetimes, \
2525
pick_unused_port, is_http_running_on, gcs_copy_file
2626

27-
__all__ = ['async', 'async_function', 'async_method', 'GCPJob', 'Http', 'RequestException',
27+
__all__ = ['async_', 'async_function', 'async_method', 'GCPJob', 'Http', 'RequestException',
2828
'Iterator', 'Job', 'JobError', 'JSONEncoder', 'LRUCache', 'LambdaJob', 'DataflowJob',
2929
'print_exception_with_last_stack', 'get_item', 'compare_datetimes', 'pick_unused_port',
3030
'is_http_running_on', 'gcs_copy_file']

datalab/utils/_async.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from future.utils import with_metaclass
2424

2525

26-
class async(with_metaclass(abc.ABCMeta, object)):
26+
class async_(with_metaclass(abc.ABCMeta, object)):
2727
""" Base class for async_function/async_method. Creates a wrapped function/method that will
2828
run the original function/method on a thread pool worker thread and return a Job instance
2929
for monitoring the status of the thread.
@@ -55,27 +55,27 @@ def __call__(self, *args, **kwargs):
5555
return _job.Job(future=self.executor.submit(self._call, *args, **kwargs))
5656

5757

58-
class async_function(async):
58+
class async_function(async_):
5959
""" This decorator can be applied to any static function that makes blocking calls to create
6060
a modified version that creates a Job and returns immediately; the original
6161
method will be called on a thread pool worker thread.
6262
"""
6363

6464
def _call(self, *args, **kwargs):
6565
# Call the wrapped method.
66-
return self._function(*async._preprocess_args(*args), **async._preprocess_kwargs(**kwargs))
66+
return self._function(*async_._preprocess_args(*args), **async_._preprocess_kwargs(**kwargs))
6767

6868

69-
class async_method(async):
69+
class async_method(async_):
7070
""" This decorator can be applied to any class instance method that makes blocking calls to create
7171
a modified version that creates a Job and returns immediately; the original method will be
7272
called on a thread pool worker thread.
7373
"""
7474

7575
def _call(self, *args, **kwargs):
7676
# Call the wrapped method.
77-
return self._function(self.obj, *async._preprocess_args(*args),
78-
**async._preprocess_kwargs(**kwargs))
77+
return self._function(self.obj, *async_._preprocess_args(*args),
78+
**async_._preprocess_kwargs(**kwargs))
7979

8080
def __get__(self, instance, owner):
8181
# This is important for attribute inheritance and setting self.obj so it can be

datalab/utils/_lambda_job.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(self, fn, job_id, *args, **kwargs):
3030
job_id: an optional ID for the job. If None, a UUID will be generated.
3131
"""
3232
super(LambdaJob, self).__init__(job_id)
33-
self._future = _async.async.executor.submit(fn, *args, **kwargs)
33+
self._future = _async.async_.executor.submit(fn, *args, **kwargs)
3434

3535
def __repr__(self):
3636
"""Returns a representation for the job for showing in the notebook.

google/datalab/utils/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
"""Google Cloud Platform library - Internal Helpers."""
1414

15-
from ._async import async, async_function, async_method
15+
from ._async import async_, async_function, async_method
1616
from ._http import Http, RequestException
1717
from ._iterator import Iterator
1818
from ._json_encoder import JSONEncoder
@@ -23,7 +23,7 @@
2323
pick_unused_port, is_http_running_on, gcs_copy_file, python_portable_string
2424

2525

26-
__all__ = ['async', 'async_function', 'async_method', 'Http', 'RequestException', 'Iterator',
26+
__all__ = ['async_', 'async_function', 'async_method', 'Http', 'RequestException', 'Iterator',
2727
'JSONEncoder', 'LRUCache', 'LambdaJob', 'DataflowJob',
2828
'print_exception_with_last_stack', 'get_item', 'compare_datetimes', 'pick_unused_port',
2929
'is_http_running_on', 'gcs_copy_file', 'python_portable_string']

google/datalab/utils/_async.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from future.utils import with_metaclass
2424

2525

26-
class async(with_metaclass(abc.ABCMeta, object)):
26+
class async_(with_metaclass(abc.ABCMeta, object)):
2727
""" Base class for async_function/async_method. Creates a wrapped function/method that will
2828
run the original function/method on a thread pool worker thread and return a Job instance
2929
for monitoring the status of the thread.
@@ -55,27 +55,27 @@ def __call__(self, *args, **kwargs):
5555
return Job(future=self.executor.submit(self._call, *args, **kwargs))
5656

5757

58-
class async_function(async):
58+
class async_function(async_):
5959
""" This decorator can be applied to any static function that makes blocking calls to create
6060
a modified version that creates a Job and returns immediately; the original
6161
method will be called on a thread pool worker thread.
6262
"""
6363

6464
def _call(self, *args, **kwargs):
6565
# Call the wrapped method.
66-
return self._function(*async._preprocess_args(*args), **async._preprocess_kwargs(**kwargs))
66+
return self._function(*async_._preprocess_args(*args), **async_._preprocess_kwargs(**kwargs))
6767

6868

69-
class async_method(async):
69+
class async_method(async_):
7070
""" This decorator can be applied to any class instance method that makes blocking calls to create
7171
a modified version that creates a Job and returns immediately; the original method will be
7272
called on a thread pool worker thread.
7373
"""
7474

7575
def _call(self, *args, **kwargs):
7676
# Call the wrapped method.
77-
return self._function(self.obj, *async._preprocess_args(*args),
78-
**async._preprocess_kwargs(**kwargs))
77+
return self._function(self.obj, *async_._preprocess_args(*args),
78+
**async_._preprocess_kwargs(**kwargs))
7979

8080
def __get__(self, instance, owner):
8181
# This is important for attribute inheritance and setting self.obj so it can be

google/datalab/utils/_lambda_job.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(self, fn, job_id, *args, **kwargs):
3030
job_id: an optional ID for the job. If None, a UUID will be generated.
3131
"""
3232
super(LambdaJob, self).__init__(job_id)
33-
self._future = _async.async.executor.submit(fn, *args, **kwargs)
33+
self._future = _async.async_.executor.submit(fn, *args, **kwargs)
3434

3535
def __repr__(self):
3636
"""Returns a representation for the job for showing in the notebook.

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
classifiers=[
7979
"Programming Language :: Python",
8080
"Programming Language :: Python :: 2",
81+
"Programming Language :: Python :: 3",
8182
"Development Status :: 4 - Beta",
8283
"Environment :: Other Environment",
8384
"Intended Audience :: Developers",

tox.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tox]
2-
# By default, we want to run tests for Python 2.7, Python 3.5, and run our
3-
# flake8 checks.
4-
envlist = py27,py35,flake8,coveralls
2+
# By default, we want to run tests for Python 2.7, Python 3.5, Python 3.7,
3+
# and run our flake8 checks.
4+
envlist = py27,py35,py37,flake8,coveralls
55
# If an interpreter is missing locally, skip it.
66
skip_missing_interpreters = true
77

0 commit comments

Comments
 (0)