Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(python): use black==22.3.0 #362

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/.OwlBot.lock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# limitations under the License.
docker:
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
digest: sha256:6162c384d685c5fe22521d3f37f6fc732bf99a085f6d47b677dbcae97fc21392
digest: sha256:7cffbc10910c3ab1b852c05114a08d374c195a81cdec1d4a67a1d129331d0bfe
13 changes: 11 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,13 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(root_doc, "google-api-core", "google-api-core Documentation", [author], 1,)
(
root_doc,
"google-api-core",
"google-api-core Documentation",
[author],
1,
)
]

# If true, show URL addresses after external links.
Expand Down Expand Up @@ -355,7 +361,10 @@
intersphinx_mapping = {
"python": ("https://python.readthedocs.org/en/latest/", None),
"google-auth": ("https://googleapis.dev/python/google-auth/latest/", None),
"google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None,),
"google.api_core": (
"https://googleapis.dev/python/google-api-core/latest/",
None,
),
"grpc": ("https://grpc.github.io/grpc/python/", None),
"proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None),
"protobuf": ("https://googleapis.dev/python/protobuf/latest/", None),
Expand Down
4 changes: 2 additions & 2 deletions google/api_core/datetime_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def from_rfc3339(value):
micros = 0
else:
scale = 9 - len(fraction)
nanos = int(fraction) * (10 ** scale)
nanos = int(fraction) * (10**scale)
micros = nanos // 1000

return bare_seconds.replace(microsecond=micros, tzinfo=datetime.timezone.utc)
Expand Down Expand Up @@ -245,7 +245,7 @@ def from_rfc3339(cls, stamp):
nanos = 0
else:
scale = 9 - len(fraction)
nanos = int(fraction) * (10 ** scale)
nanos = int(fraction) * (10**scale)
return cls(
bare.year,
bare.month,
Expand Down
6 changes: 4 additions & 2 deletions google/api_core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def details(self):

Returns:
Sequence[Any]: A list of structured objects from error_details.proto
"""
"""
return list(self._details)

@property
Expand Down Expand Up @@ -490,7 +490,9 @@ def from_http_response(response):
error_info = error_info[0] if error_info else None

message = "{method} {url}: {error}".format(
method=response.request.method, url=response.request.url, error=error_message,
method=response.request.method,
url=response.request.url,
error=error_message,
)

exception = from_http_status(
Expand Down
4 changes: 3 additions & 1 deletion google/api_core/grpc_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ def _create_composite_credentials(

# Create the metadata plugin for inserting the authorization header.
metadata_plugin = google.auth.transport.grpc.AuthMetadataPlugin(
credentials, request, default_host=default_host,
credentials,
request,
default_host=default_host,
)

# Create a set of grpc.CallCredentials using the metadata plugin.
Expand Down
68 changes: 53 additions & 15 deletions google/api_core/operations_v1/abstract_operations_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class AbstractOperationsClientMeta(type):
_transport_registry["rest"] = OperationsRestTransport

def get_transport_class(
cls, label: Optional[str] = None,
cls,
label: Optional[str] = None,
) -> Type[OperationsTransport]:
"""Returns an appropriate transport class.

Expand Down Expand Up @@ -165,7 +166,9 @@ def transport(self) -> OperationsTransport:
return self._transport

@staticmethod
def common_billing_account_path(billing_account: str,) -> str:
def common_billing_account_path(
billing_account: str,
) -> str:
"""Returns a fully-qualified billing_account string."""
return "billingAccounts/{billing_account}".format(
billing_account=billing_account,
Expand All @@ -178,9 +181,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]:
return m.groupdict() if m else {}

@staticmethod
def common_folder_path(folder: str,) -> str:
def common_folder_path(
folder: str,
) -> str:
"""Returns a fully-qualified folder string."""
return "folders/{folder}".format(folder=folder,)
return "folders/{folder}".format(
folder=folder,
)

@staticmethod
def parse_common_folder_path(path: str) -> Dict[str, str]:
Expand All @@ -189,9 +196,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]:
return m.groupdict() if m else {}

@staticmethod
def common_organization_path(organization: str,) -> str:
def common_organization_path(
organization: str,
) -> str:
"""Returns a fully-qualified organization string."""
return "organizations/{organization}".format(organization=organization,)
return "organizations/{organization}".format(
organization=organization,
)

@staticmethod
def parse_common_organization_path(path: str) -> Dict[str, str]:
Expand All @@ -200,9 +211,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]:
return m.groupdict() if m else {}

@staticmethod
def common_project_path(project: str,) -> str:
def common_project_path(
project: str,
) -> str:
"""Returns a fully-qualified project string."""
return "projects/{project}".format(project=project,)
return "projects/{project}".format(
project=project,
)

@staticmethod
def parse_common_project_path(path: str) -> Dict[str, str]:
Expand All @@ -211,10 +226,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]:
return m.groupdict() if m else {}

@staticmethod
def common_location_path(project: str, location: str,) -> str:
def common_location_path(
project: str,
location: str,
) -> str:
"""Returns a fully-qualified location string."""
return "projects/{project}/locations/{location}".format(
project=project, location=location,
project=project,
location=location,
)

@staticmethod
Expand Down Expand Up @@ -406,12 +425,20 @@ def list_operations(
)

# Send the request.
response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
response = rpc(
request,
retry=retry,
timeout=timeout,
metadata=metadata,
)

# This method is paged; wrap the response in a pager, which provides
# an `__iter__` convenience method.
response = pagers.ListOperationsPager(
method=rpc, request=request, response=response, metadata=metadata,
method=rpc,
request=request,
response=response,
metadata=metadata,
)

# Done; return the response.
Expand Down Expand Up @@ -459,7 +486,12 @@ def get_operation(
)

# Send the request.
response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
response = rpc(
request,
retry=retry,
timeout=timeout,
metadata=metadata,
)

# Done; return the response.
return response
Expand Down Expand Up @@ -506,7 +538,10 @@ def delete_operation(

# Send the request.
rpc(
request, retry=retry, timeout=timeout, metadata=metadata,
request,
retry=retry,
timeout=timeout,
metadata=metadata,
)

def cancel_operation(
Expand Down Expand Up @@ -560,5 +595,8 @@ def cancel_operation(

# Send the request.
rpc(
request, retry=retry, timeout=timeout, metadata=metadata,
request,
retry=retry,
timeout=timeout,
metadata=metadata,
)
6 changes: 3 additions & 3 deletions google/api_core/operations_v1/transports/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ def _prep_wrapped_messages(self, client_info):
def close(self):
"""Closes resources associated with the transport.

.. warning::
Only call this method if the transport is NOT shared
with other clients - this may cause errors in other clients!
.. warning::
Only call this method if the transport is NOT shared
with other clients - this may cause errors in other clients!
"""
raise NotImplementedError()

Expand Down
40 changes: 20 additions & 20 deletions google/api_core/path_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,26 +239,26 @@ def validate(tmpl, path):

def transcode(http_options, **request_kwargs):
"""Transcodes a grpc request pattern into a proper HTTP request following the rules outlined here,
https://github.com/googleapis/googleapis/blob/master/google/api/http.proto#L44-L312

Args:
http_options (list(dict)): A list of dicts which consist of these keys,
'method' (str): The http method
'uri' (str): The path template
'body' (str): The body field name (optional)
(This is a simplified representation of the proto option `google.api.http`)

request_kwargs (dict) : A dict representing the request object

Returns:
dict: The transcoded request with these keys,
'method' (str) : The http method
'uri' (str) : The expanded uri
'body' (dict) : A dict representing the body (optional)
'query_params' (dict) : A dict mapping query parameter variables and values

Raises:
ValueError: If the request does not match the given template.
https://github.com/googleapis/googleapis/blob/master/google/api/http.proto#L44-L312

Args:
http_options (list(dict)): A list of dicts which consist of these keys,
'method' (str): The http method
'uri' (str): The path template
'body' (str): The body field name (optional)
(This is a simplified representation of the proto option `google.api.http`)

request_kwargs (dict) : A dict representing the request object

Returns:
dict: The transcoded request with these keys,
'method' (str) : The http method
'uri' (str) : The expanded uri
'body' (dict) : A dict representing the body (optional)
'query_params' (dict) : A dict mapping query parameter variables and values

Raises:
ValueError: If the request does not match the given template.
"""
for http_option in http_options:
request = {}
Expand Down
3 changes: 1 addition & 2 deletions google/api_core/rest_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ def __init__(self, response: requests.Response, response_message_cls):
self._escape_next = False

def cancel(self):
"""Cancel existing streaming operation.
"""
"""Cancel existing streaming operation."""
self._response.close()

def _process_chunk(self, chunk: str):
Expand Down
7 changes: 5 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import nox # pytype: disable=import-error


BLACK_VERSION = "black==19.10b0"
BLACK_VERSION = "black==22.3.0"
BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]
# Black and flake8 clash on the syntax for ignoring flake8's F401 in this file.
BLACK_EXCLUDES = ["--exclude", "^/google/api_core/operations_v1/__init__.py"]
Expand Down Expand Up @@ -64,7 +64,10 @@ def lint(session):
session.install("flake8", "flake8-import-order", BLACK_VERSION)
session.install(".")
session.run(
"black", "--check", *BLACK_EXCLUDES, *BLACK_PATHS,
"black",
"--check",
*BLACK_EXCLUDES,
*BLACK_PATHS,
)
session.run("flake8", "google", "tests")

Expand Down
3 changes: 2 additions & 1 deletion tests/asyncio/gapic/test_method_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ async def test_wrap_method_with_default_retry_and_timeout_using_sentinel(unused_
)

result = await wrapped_method(
retry=gapic_v1.method_async.DEFAULT, timeout=gapic_v1.method_async.DEFAULT,
retry=gapic_v1.method_async.DEFAULT,
timeout=gapic_v1.method_async.DEFAULT,
)

assert result == 42
Expand Down
Loading