diff --git a/core/.flake8 b/core/.flake8 index 25168dc87605..7f4ddb8072b0 100644 --- a/core/.flake8 +++ b/core/.flake8 @@ -1,4 +1,5 @@ [flake8] +import-order-style=google exclude = __pycache__, .git, diff --git a/core/google/__init__.py b/core/google/__init__.py index b2b833373882..a35569c36339 100644 --- a/core/google/__init__.py +++ b/core/google/__init__.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Google namespace package.""" + try: import pkg_resources pkg_resources.declare_namespace(__name__) diff --git a/core/google/cloud/__init__.py b/core/google/cloud/__init__.py index b2b833373882..59a804265f5c 100644 --- a/core/google/cloud/__init__.py +++ b/core/google/cloud/__init__.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Google Cloud namespace package.""" + try: import pkg_resources pkg_resources.declare_namespace(__name__) diff --git a/core/google/cloud/_helpers.py b/core/google/cloud/_helpers.py index 72918e064507..62bbccf74b15 100644 --- a/core/google/cloud/_helpers.py +++ b/core/google/cloud/_helpers.py @@ -17,7 +17,6 @@ This module is not part of the public API surface. """ -# Avoid the grpc and google.cloud.grpc collision. from __future__ import absolute_import import calendar @@ -104,7 +103,7 @@ def top(self): :rtype: object :returns: the top-most item, or None if the stack is empty. """ - if len(self._stack) > 0: + if self._stack: return self._stack[-1] diff --git a/core/google/cloud/_http.py b/core/google/cloud/_http.py index e1a481e581a7..ada60b4fb2c3 100644 --- a/core/google/cloud/_http.py +++ b/core/google/cloud/_http.py @@ -279,7 +279,9 @@ def api_request(self, method, path, query_params=None, can allow custom behavior, for example, to defer an HTTP request and complete initialization of the object at a later time. - :raises: Exception if the response code is not 200 OK. + :raises ~google.cloud.exceptions.GoogleCloudError: if the response code + is not 200 OK. + :raises TypeError: if the response content type is not JSON. :rtype: dict or str :returns: The API response payload, either as a raw string or a dictionary if the response is valid JSON. diff --git a/core/google/cloud/_testing.py b/core/google/cloud/_testing.py index a544fffc5fe4..871b5f631bc7 100644 --- a/core/google/cloud/_testing.py +++ b/core/google/cloud/_testing.py @@ -14,17 +14,15 @@ """Shared testing utilities.""" - -# Avoid the grpc and google.cloud.grpc collision. from __future__ import absolute_import class _Monkey(object): - # context-manager for replacing module names in the scope of a test. + """Context-manager for replacing module names in the scope of a test.""" def __init__(self, module, **kw): self.module = module - if len(kw) == 0: # pragma: NO COVER + if not kw: # pragma: NO COVER raise ValueError('_Monkey was used with nothing to monkey-patch') self.to_restore = {key: getattr(module, key) for key in kw} for key, value in kw.items(): @@ -68,8 +66,12 @@ def _tempdir_mgr(): return _tempdir_mgr +# pylint: disable=invalid-name +# Retain _tempdir as a constant for backwards compatibility despite +# being an invalid name. _tempdir = _tempdir_maker() del _tempdir_maker +# pylint: enable=invalid-name class _GAXBaseAPI(object): @@ -79,7 +81,8 @@ class _GAXBaseAPI(object): def __init__(self, **kw): self.__dict__.update(kw) - def _make_grpc_error(self, status_code, trailing=None): + @staticmethod + def _make_grpc_error(status_code, trailing=None): from grpc._channel import _RPCState from google.cloud.exceptions import GrpcRendezvous @@ -111,6 +114,7 @@ def __init__(self, *pages, **kwargs): self.page_token = kwargs.get('page_token') def next(self): + """Iterate to the next page.""" import six return six.next(self._pages) diff --git a/core/google/cloud/client.py b/core/google/cloud/client.py index 9bdbf507d201..5fa7f7ef95a2 100644 --- a/core/google/cloud/client.py +++ b/core/google/cloud/client.py @@ -64,7 +64,7 @@ def from_service_account_json(cls, json_credentials_path, *args, **kwargs): :rtype: :class:`_ClientFactoryMixin` :returns: The client created with the retrieved JSON credentials. - :raises: :class:`TypeError` if there is a conflict with the kwargs + :raises TypeError: if there is a conflict with the kwargs and the credentials created by the factory. """ if 'credentials' in kwargs: diff --git a/core/google/cloud/future/operation.py b/core/google/cloud/future/operation.py index 5bbfda1a8f0b..8064e5c13e1f 100644 --- a/core/google/cloud/future/operation.py +++ b/core/google/cloud/future/operation.py @@ -34,7 +34,7 @@ class Operation(base.PollingFuture): initial operation. refresh (Callable[[], Operation]): A callable that returns the latest state of the operation. - cancel (Callable[[], None]), A callable that tries to cancel + cancel (Callable[[], None]): A callable that tries to cancel the operation. result_type (type): The protobuf type for the operation's result. metadata_type (type): The protobuf type for the operation's diff --git a/core/google/cloud/iam.py b/core/google/cloud/iam.py index 49bb11266cee..bbc31c047a85 100644 --- a/core/google/cloud/iam.py +++ b/core/google/cloud/iam.py @@ -226,14 +226,14 @@ def to_api_repr(self): if self.version is not None: resource['version'] = self.version - if len(self._bindings) > 0: + if self._bindings: bindings = resource['bindings'] = [] for role, members in sorted(self._bindings.items()): - if len(members) > 0: + if members: bindings.append( {'role': role, 'members': sorted(set(members))}) - if len(bindings) == 0: + if not bindings: del resource['bindings'] return resource diff --git a/core/google/cloud/iterator.py b/core/google/cloud/iterator.py index 7bb708e90f09..742443ddc5f9 100644 --- a/core/google/cloud/iterator.py +++ b/core/google/cloud/iterator.py @@ -242,7 +242,8 @@ def _page_iter(self, increment): results per page while an items iterator will want to increment per item. - Yields :class:`Page` instances. + :rtype: :class:`Page` + :returns: pages """ page = self._next_page() while page is not None: @@ -387,6 +388,8 @@ def _get_next_page_response(self): :rtype: dict :returns: The parsed JSON response of the next page's contents. + + :raises ValueError: If the HTTP method is not ``GET`` or ``POST``. """ params = self._get_query_params() if self._HTTP_METHOD == 'GET': diff --git a/core/google/cloud/operation.py b/core/google/cloud/operation.py index 4e700a553e4f..9f53c595f658 100644 --- a/core/google/cloud/operation.py +++ b/core/google/cloud/operation.py @@ -50,7 +50,7 @@ def register_type(klass, type_url=None): :param type_url: (Optional) URL naming the type. If not provided, infers the URL from the type descriptor. - :raises: ValueError if a registration already exists for the URL. + :raises ValueError: if a registration already exists for the URL. """ if type_url is None: type_url = _compute_type_url(klass) @@ -258,7 +258,7 @@ def poll(self): :rtype: bool :returns: A boolean indicating if the current operation has completed. - :raises: :class:`~exceptions.ValueError` if the operation + :raises ValueError: if the operation has already completed. """ if self.complete: diff --git a/core/nox.py b/core/nox.py index c8f4a942e7a2..8f025cce8b61 100644 --- a/core/nox.py +++ b/core/nox.py @@ -50,7 +50,8 @@ def lint(session): serious code quality issues. """ session.interpreter = 'python3.6' - session.install('flake8', 'pylint', 'gcp-devrel-py-tools') + session.install( + 'flake8', 'flake8-import-order', 'pylint', 'gcp-devrel-py-tools') session.install('.') session.run('flake8', 'google/cloud/core') session.run(