From be2a24d15c5dc2095e8bcb7b3a42137e2c239281 Mon Sep 17 00:00:00 2001 From: Nat Noordanus Date: Wed, 27 May 2020 10:56:12 +0200 Subject: [PATCH] blacken --- betterproto/__init__.py | 8 +++-- betterproto/plugin.py | 34 ++++++++++++------- .../tests/inputs/service/test_service.py | 2 +- conftest.py | 4 ++- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/betterproto/__init__.py b/betterproto/__init__.py index 81ff81b..11fb741 100644 --- a/betterproto/__init__.py +++ b/betterproto/__init__.py @@ -652,7 +652,9 @@ class Message(ABC): return self._betterproto.default_gen[field.name]() @classmethod - def _get_field_default_gen(cls, field: dataclasses.Field, meta: FieldMetadata) -> Any: + def _get_field_default_gen( + cls, field: dataclasses.Field, meta: FieldMetadata + ) -> Any: t = cls._type_hint(field.name) if hasattr(t, "__origin__"): @@ -831,7 +833,9 @@ class Message(ABC): else: output[cased_name] = b64encode(v).decode("utf8") elif meta.proto_type == TYPE_ENUM: - enum_values = list(self._betterproto.cls_by_field[field.name]) # type: ignore + enum_values = list( + self._betterproto.cls_by_field[field.name] + ) # type: ignore if isinstance(v, list): output[cased_name] = [enum_values[e].name for e in v] else: diff --git a/betterproto/plugin.py b/betterproto/plugin.py index 2184a9c..7f2a882 100755 --- a/betterproto/plugin.py +++ b/betterproto/plugin.py @@ -29,20 +29,25 @@ from betterproto.casing import safe_snake_case import google.protobuf.wrappers_pb2 as google_wrappers -WRAPPER_TYPES: Dict[str, Optional[Type]] = defaultdict(lambda: None, { - 'google.protobuf.DoubleValue': google_wrappers.DoubleValue, - 'google.protobuf.FloatValue': google_wrappers.FloatValue, - 'google.protobuf.Int64Value': google_wrappers.Int64Value, - 'google.protobuf.UInt64Value': google_wrappers.UInt64Value, - 'google.protobuf.Int32Value': google_wrappers.Int32Value, - 'google.protobuf.UInt32Value': google_wrappers.UInt32Value, - 'google.protobuf.BoolValue': google_wrappers.BoolValue, - 'google.protobuf.StringValue': google_wrappers.StringValue, - 'google.protobuf.BytesValue': google_wrappers.BytesValue, -}) +WRAPPER_TYPES: Dict[str, Optional[Type]] = defaultdict( + lambda: None, + { + "google.protobuf.DoubleValue": google_wrappers.DoubleValue, + "google.protobuf.FloatValue": google_wrappers.FloatValue, + "google.protobuf.Int64Value": google_wrappers.Int64Value, + "google.protobuf.UInt64Value": google_wrappers.UInt64Value, + "google.protobuf.Int32Value": google_wrappers.Int32Value, + "google.protobuf.UInt32Value": google_wrappers.UInt32Value, + "google.protobuf.BoolValue": google_wrappers.BoolValue, + "google.protobuf.StringValue": google_wrappers.StringValue, + "google.protobuf.BytesValue": google_wrappers.BytesValue, + }, +) -def get_ref_type(package: str, imports: set, type_name: str, unwrap: bool = True) -> str: +def get_ref_type( + package: str, imports: set, type_name: str, unwrap: bool = True +) -> str: """ Return a Python type name for a proto type reference. Adds the import if necessary. Unwraps well known type if required. @@ -385,7 +390,10 @@ def generate_code(request, response): ).strip('"'), "input_message": input_message, "output": get_ref_type( - package, output["imports"], method.output_type, unwrap=False + package, + output["imports"], + method.output_type, + unwrap=False, ).strip('"'), "client_streaming": method.client_streaming, "server_streaming": method.server_streaming, diff --git a/betterproto/tests/inputs/service/test_service.py b/betterproto/tests/inputs/service/test_service.py index ebd9308..2a6ca59 100644 --- a/betterproto/tests/inputs/service/test_service.py +++ b/betterproto/tests/inputs/service/test_service.py @@ -34,7 +34,7 @@ class ExampleService: grpclib.const.Cardinality.UNARY_UNARY, DoThingRequest, DoThingResponse, - ), + ) } diff --git a/conftest.py b/conftest.py index 1727782..6ab4f03 100644 --- a/conftest.py +++ b/conftest.py @@ -2,7 +2,9 @@ import pytest def pytest_addoption(parser): - parser.addoption("--repeat", type=int, default=1, help="repeat the operation multiple times") + parser.addoption( + "--repeat", type=int, default=1, help="repeat the operation multiple times" + ) @pytest.fixture(scope="session")