Skip to content
This repository was archived by the owner on Feb 1, 2024. It is now read-only.

Commit 1e9b80e

Browse files
authored
Avoid overwriting '__module__' of messages from shared modules. (#5364)
Note that we *are* still overwriting it for messages from modules defined within the current package. See #4715.
1 parent 51425c8 commit 1e9b80e

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

google/cloud/tasks_v2beta2/types.py

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@
1515
from __future__ import absolute_import
1616
import sys
1717

18-
from google.api_core.protobuf_helpers import get_messages
19-
2018
from google.api import http_pb2
21-
from google.cloud.tasks_v2beta2.proto import cloudtasks_pb2
22-
from google.cloud.tasks_v2beta2.proto import queue_pb2
23-
from google.cloud.tasks_v2beta2.proto import target_pb2
24-
from google.cloud.tasks_v2beta2.proto import task_pb2
2519
from google.iam.v1 import iam_policy_pb2
2620
from google.iam.v1 import policy_pb2
2721
from google.protobuf import any_pb2
@@ -32,23 +26,41 @@
3226
from google.protobuf import timestamp_pb2
3327
from google.rpc import status_pb2
3428

29+
from google.api_core.protobuf_helpers import get_messages
30+
from google.cloud.tasks_v2beta2.proto import cloudtasks_pb2
31+
from google.cloud.tasks_v2beta2.proto import queue_pb2
32+
from google.cloud.tasks_v2beta2.proto import target_pb2
33+
from google.cloud.tasks_v2beta2.proto import task_pb2
34+
35+
36+
_shared_modules = [
37+
http_pb2,
38+
iam_policy_pb2,
39+
policy_pb2,
40+
any_pb2,
41+
descriptor_pb2,
42+
duration_pb2,
43+
empty_pb2,
44+
field_mask_pb2,
45+
timestamp_pb2,
46+
status_pb2,
47+
]
48+
49+
_local_modules = [
50+
cloudtasks_pb2,
51+
queue_pb2,
52+
target_pb2,
53+
task_pb2,
54+
]
55+
3556
names = []
36-
for module in (
37-
http_pb2,
38-
cloudtasks_pb2,
39-
queue_pb2,
40-
target_pb2,
41-
task_pb2,
42-
iam_policy_pb2,
43-
policy_pb2,
44-
any_pb2,
45-
descriptor_pb2,
46-
duration_pb2,
47-
empty_pb2,
48-
field_mask_pb2,
49-
timestamp_pb2,
50-
status_pb2,
51-
):
57+
58+
for module in _shared_modules:
59+
for name, message in get_messages(module).items():
60+
setattr(sys.modules[__name__], name, message)
61+
names.append(name)
62+
63+
for module in _local_modules:
5264
for name, message in get_messages(module).items():
5365
message.__module__ = 'google.cloud.tasks_v2beta2.types'
5466
setattr(sys.modules[__name__], name, message)

0 commit comments

Comments
 (0)