From 9072c7f82ee888dd5df99dcd04bf12a65e1a695c Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Tue, 22 May 2018 16:03:07 -0400 Subject: [PATCH] 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. --- .../cloud/videointelligence_v1/types.py | 40 +++++++++++------- .../cloud/videointelligence_v1beta1/types.py | 38 +++++++++++------ .../cloud/videointelligence_v1beta2/types.py | 40 +++++++++++------- .../videointelligence_v1p1beta1/types.py | 41 ++++++++++++------- 4 files changed, 104 insertions(+), 55 deletions(-) diff --git a/packages/google-cloud-videointelligence/google/cloud/videointelligence_v1/types.py b/packages/google-cloud-videointelligence/google/cloud/videointelligence_v1/types.py index 4d34475d179a..1d59ad8f3b76 100644 --- a/packages/google-cloud-videointelligence/google/cloud/videointelligence_v1/types.py +++ b/packages/google-cloud-videointelligence/google/cloud/videointelligence_v1/types.py @@ -15,10 +15,7 @@ from __future__ import absolute_import import sys -from google.api_core.protobuf_helpers import get_messages - from google.api import http_pb2 -from google.cloud.videointelligence_v1.proto import video_intelligence_pb2 from google.longrunning import operations_pb2 from google.protobuf import any_pb2 from google.protobuf import descriptor_pb2 @@ -27,18 +24,33 @@ from google.protobuf import timestamp_pb2 from google.rpc import status_pb2 +from google.api_core.protobuf_helpers import get_messages +from google.cloud.videointelligence_v1.proto import video_intelligence_pb2 + + +_shared_modules = [ + http_pb2, + operations_pb2, + any_pb2, + descriptor_pb2, + duration_pb2, + empty_pb2, + timestamp_pb2, + status_pb2, +] + +_local_modules = [ + video_intelligence_pb2, +] + names = [] -for module in ( - http_pb2, - video_intelligence_pb2, - operations_pb2, - any_pb2, - descriptor_pb2, - duration_pb2, - empty_pb2, - timestamp_pb2, - status_pb2, -): + +for module in _shared_modules: + for name, message in get_messages(module).items(): + setattr(sys.modules[__name__], name, message) + names.append(name) + +for module in _local_modules: for name, message in get_messages(module).items(): message.__module__ = 'google.cloud.videointelligence_v1.types' setattr(sys.modules[__name__], name, message) diff --git a/packages/google-cloud-videointelligence/google/cloud/videointelligence_v1beta1/types.py b/packages/google-cloud-videointelligence/google/cloud/videointelligence_v1beta1/types.py index 49c0459d2fea..35dd7b2abd3e 100644 --- a/packages/google-cloud-videointelligence/google/cloud/videointelligence_v1beta1/types.py +++ b/packages/google-cloud-videointelligence/google/cloud/videointelligence_v1beta1/types.py @@ -15,10 +15,7 @@ from __future__ import absolute_import import sys -from google.api_core.protobuf_helpers import get_messages - from google.api import http_pb2 -from google.cloud.videointelligence_v1beta1.proto import video_intelligence_pb2 from google.longrunning import operations_pb2 from google.protobuf import any_pb2 from google.protobuf import descriptor_pb2 @@ -26,17 +23,32 @@ from google.protobuf import timestamp_pb2 from google.rpc import status_pb2 +from google.api_core.protobuf_helpers import get_messages +from google.cloud.videointelligence_v1beta1.proto import video_intelligence_pb2 + + +_shared_modules = [ + http_pb2, + operations_pb2, + any_pb2, + descriptor_pb2, + empty_pb2, + timestamp_pb2, + status_pb2, +] + +_local_modules = [ + video_intelligence_pb2, +] + names = [] -for module in ( - http_pb2, - video_intelligence_pb2, - operations_pb2, - any_pb2, - descriptor_pb2, - empty_pb2, - timestamp_pb2, - status_pb2, -): + +for module in _shared_modules: + for name, message in get_messages(module).items(): + setattr(sys.modules[__name__], name, message) + names.append(name) + +for module in _local_modules: for name, message in get_messages(module).items(): message.__module__ = 'google.cloud.videointelligence_v1beta1.types' setattr(sys.modules[__name__], name, message) diff --git a/packages/google-cloud-videointelligence/google/cloud/videointelligence_v1beta2/types.py b/packages/google-cloud-videointelligence/google/cloud/videointelligence_v1beta2/types.py index da516eb8b06d..4772f678a773 100644 --- a/packages/google-cloud-videointelligence/google/cloud/videointelligence_v1beta2/types.py +++ b/packages/google-cloud-videointelligence/google/cloud/videointelligence_v1beta2/types.py @@ -15,10 +15,7 @@ from __future__ import absolute_import import sys -from google.api_core.protobuf_helpers import get_messages - from google.api import http_pb2 -from google.cloud.videointelligence_v1beta2.proto import video_intelligence_pb2 from google.longrunning import operations_pb2 from google.protobuf import any_pb2 from google.protobuf import descriptor_pb2 @@ -27,18 +24,33 @@ from google.protobuf import timestamp_pb2 from google.rpc import status_pb2 +from google.api_core.protobuf_helpers import get_messages +from google.cloud.videointelligence_v1beta2.proto import video_intelligence_pb2 + + +_shared_modules = [ + http_pb2, + operations_pb2, + any_pb2, + descriptor_pb2, + duration_pb2, + empty_pb2, + timestamp_pb2, + status_pb2, +] + +_local_modules = [ + video_intelligence_pb2, +] + names = [] -for module in ( - http_pb2, - video_intelligence_pb2, - operations_pb2, - any_pb2, - descriptor_pb2, - duration_pb2, - empty_pb2, - timestamp_pb2, - status_pb2, -): + +for module in _shared_modules: + for name, message in get_messages(module).items(): + setattr(sys.modules[__name__], name, message) + names.append(name) + +for module in _local_modules: for name, message in get_messages(module).items(): message.__module__ = 'google.cloud.videointelligence_v1beta2.types' setattr(sys.modules[__name__], name, message) diff --git a/packages/google-cloud-videointelligence/google/cloud/videointelligence_v1p1beta1/types.py b/packages/google-cloud-videointelligence/google/cloud/videointelligence_v1p1beta1/types.py index fabf956b94c6..90a88ae5f49c 100644 --- a/packages/google-cloud-videointelligence/google/cloud/videointelligence_v1p1beta1/types.py +++ b/packages/google-cloud-videointelligence/google/cloud/videointelligence_v1p1beta1/types.py @@ -15,10 +15,7 @@ from __future__ import absolute_import import sys -from google.api_core.protobuf_helpers import get_messages - from google.api import http_pb2 -from google.cloud.videointelligence_v1p1beta1.proto import video_intelligence_pb2 from google.longrunning import operations_pb2 from google.protobuf import any_pb2 from google.protobuf import descriptor_pb2 @@ -27,18 +24,34 @@ from google.protobuf import timestamp_pb2 from google.rpc import status_pb2 +from google.api_core.protobuf_helpers import get_messages +from google.cloud.videointelligence_v1p1beta1.proto import ( + video_intelligence_pb2) + + +_shared_modules = [ + http_pb2, + operations_pb2, + any_pb2, + descriptor_pb2, + duration_pb2, + empty_pb2, + timestamp_pb2, + status_pb2, +] + +_local_modules = [ + video_intelligence_pb2, +] + names = [] -for module in ( - http_pb2, - video_intelligence_pb2, - operations_pb2, - any_pb2, - descriptor_pb2, - duration_pb2, - empty_pb2, - timestamp_pb2, - status_pb2, -): + +for module in _shared_modules: + for name, message in get_messages(module).items(): + setattr(sys.modules[__name__], name, message) + names.append(name) + +for module in _local_modules: for name, message in get_messages(module).items(): message.__module__ = 'google.cloud.videointelligence_v1p1beta1.types' setattr(sys.modules[__name__], name, message)