|
29 | 29 |
|
30 | 30 | import google.protobuf.wrappers_pb2 as google_wrappers
|
31 | 31 |
|
32 |
| -WRAPPER_TYPES: Dict[str, Optional[Type]] = defaultdict(lambda: None, { |
33 |
| - 'google.protobuf.DoubleValue': google_wrappers.DoubleValue, |
34 |
| - 'google.protobuf.FloatValue': google_wrappers.FloatValue, |
35 |
| - 'google.protobuf.Int64Value': google_wrappers.Int64Value, |
36 |
| - 'google.protobuf.UInt64Value': google_wrappers.UInt64Value, |
37 |
| - 'google.protobuf.Int32Value': google_wrappers.Int32Value, |
38 |
| - 'google.protobuf.UInt32Value': google_wrappers.UInt32Value, |
39 |
| - 'google.protobuf.BoolValue': google_wrappers.BoolValue, |
40 |
| - 'google.protobuf.StringValue': google_wrappers.StringValue, |
41 |
| - 'google.protobuf.BytesValue': google_wrappers.BytesValue, |
42 |
| -}) |
43 |
| - |
44 |
| - |
45 |
| -def get_ref_type(package: str, imports: set, type_name: str, unwrap: bool = True) -> str: |
| 32 | +WRAPPER_TYPES: Dict[str, Optional[Type]] = defaultdict( |
| 33 | + lambda: None, |
| 34 | + { |
| 35 | + "google.protobuf.DoubleValue": google_wrappers.DoubleValue, |
| 36 | + "google.protobuf.FloatValue": google_wrappers.FloatValue, |
| 37 | + "google.protobuf.Int64Value": google_wrappers.Int64Value, |
| 38 | + "google.protobuf.UInt64Value": google_wrappers.UInt64Value, |
| 39 | + "google.protobuf.Int32Value": google_wrappers.Int32Value, |
| 40 | + "google.protobuf.UInt32Value": google_wrappers.UInt32Value, |
| 41 | + "google.protobuf.BoolValue": google_wrappers.BoolValue, |
| 42 | + "google.protobuf.StringValue": google_wrappers.StringValue, |
| 43 | + "google.protobuf.BytesValue": google_wrappers.BytesValue, |
| 44 | + }, |
| 45 | +) |
| 46 | + |
| 47 | + |
| 48 | +def get_ref_type( |
| 49 | + package: str, imports: set, type_name: str, unwrap: bool = True |
| 50 | +) -> str: |
46 | 51 | """
|
47 | 52 | Return a Python type name for a proto type reference. Adds the import if
|
48 | 53 | necessary. Unwraps well known type if required.
|
@@ -385,7 +390,10 @@ def generate_code(request, response):
|
385 | 390 | ).strip('"'),
|
386 | 391 | "input_message": input_message,
|
387 | 392 | "output": get_ref_type(
|
388 |
| - package, output["imports"], method.output_type, unwrap=False |
| 393 | + package, |
| 394 | + output["imports"], |
| 395 | + method.output_type, |
| 396 | + unwrap=False, |
389 | 397 | ).strip('"'),
|
390 | 398 | "client_streaming": method.client_streaming,
|
391 | 399 | "server_streaming": method.server_streaming,
|
|
0 commit comments