From 63f5f695fdc554a76f17979e549871054d6b8436 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Thu, 11 Jul 2024 14:49:32 -0400 Subject: [PATCH 1/5] fix: Remove check for Protobuf version --- proto/marshal/compat.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/proto/marshal/compat.py b/proto/marshal/compat.py index dc77f3ac..c074b250 100644 --- a/proto/marshal/compat.py +++ b/proto/marshal/compat.py @@ -21,8 +21,6 @@ from google.protobuf.internal import containers import google.protobuf -PROTOBUF_VERSION = google.protobuf.__version__ - # Import protobuf 4.xx first and fallback to earlier version # if not present. try: @@ -40,13 +38,6 @@ repeated_scalar_types = (containers.RepeatedScalarFieldContainer,) map_composite_types = (containers.MessageMap,) -# In `proto/marshal.py`, for compatibility with protobuf 5.x, -# we'll use `map_composite_type_names` to check whether -# the name of the class of a protobuf type is -# `MessageMapContainer`, and, if `True`, return a MapComposite. -# See https://github.com/protocolbuffers/protobuf/issues/16596 -map_composite_type_names = ("MessageMapContainer",) - if _message: repeated_composite_types += (_message.RepeatedCompositeContainer,) repeated_scalar_types += (_message.RepeatedScalarContainer,) @@ -56,8 +47,15 @@ # the name of the class of a protobuf type is # `MessageMapContainer`, and, if `True`, return a MapComposite. # See https://github.com/protocolbuffers/protobuf/issues/16596 - if PROTOBUF_VERSION[0:2] in ["3.", "4."]: + try: map_composite_types += (_message.MessageMapContainer,) + except: + # In `proto/marshal.py`, for compatibility with protobuf 5.x, + # we'll use `map_composite_type_names` to check whether + # the name of the class of a protobuf type is + # `MessageMapContainer`, and, if `True`, return a MapComposite. + # See https://github.com/protocolbuffers/protobuf/issues/16596 + map_composite_type_names = ("MessageMapContainer",) __all__ = ( "repeated_composite_types", From d92aa0ff579edfd1a4ef0ea8824b5da5e79a85ec Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Thu, 11 Jul 2024 19:00:17 +0000 Subject: [PATCH 2/5] restore unconditional behaviour --- proto/marshal/compat.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/proto/marshal/compat.py b/proto/marshal/compat.py index c074b250..49078ab9 100644 --- a/proto/marshal/compat.py +++ b/proto/marshal/compat.py @@ -19,7 +19,6 @@ # not be included. from google.protobuf.internal import containers -import google.protobuf # Import protobuf 4.xx first and fallback to earlier version # if not present. @@ -42,20 +41,19 @@ repeated_composite_types += (_message.RepeatedCompositeContainer,) repeated_scalar_types += (_message.RepeatedScalarContainer,) - # In `proto/marshal.py`, for compatibility with protobuf 5.x, - # we'll use `map_composite_type_names` to check whether + # For compatibility with protobuf 5.x, + # we'll fall back to `map_composite_type_names` to check whether # the name of the class of a protobuf type is # `MessageMapContainer`, and, if `True`, return a MapComposite. # See https://github.com/protocolbuffers/protobuf/issues/16596 + map_composite_type_names = ("MessageMapContainer",) + try: map_composite_types += (_message.MessageMapContainer,) except: - # In `proto/marshal.py`, for compatibility with protobuf 5.x, - # we'll use `map_composite_type_names` to check whether - # the name of the class of a protobuf type is - # `MessageMapContainer`, and, if `True`, return a MapComposite. - # See https://github.com/protocolbuffers/protobuf/issues/16596 - map_composite_type_names = ("MessageMapContainer",) + # The `MessageMapContainer` attribute is not available in Protobuf 5.x+ + pass + __all__ = ( "repeated_composite_types", From e9b6a58e7377b2ccd52f4a7b39bc3f3199c1460c Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Thu, 11 Jul 2024 19:01:21 +0000 Subject: [PATCH 3/5] restore behaviour --- proto/marshal/compat.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/proto/marshal/compat.py b/proto/marshal/compat.py index 49078ab9..742a8fdb 100644 --- a/proto/marshal/compat.py +++ b/proto/marshal/compat.py @@ -37,17 +37,17 @@ repeated_scalar_types = (containers.RepeatedScalarFieldContainer,) map_composite_types = (containers.MessageMap,) +# For compatibility with protobuf 5.x, +# we'll fall back to `map_composite_type_names` to check whether +# the name of the class of a protobuf type is +# `MessageMapContainer`, and, if `True`, return a MapComposite. +# See https://github.com/protocolbuffers/protobuf/issues/16596 +map_composite_type_names = ("MessageMapContainer",) + if _message: repeated_composite_types += (_message.RepeatedCompositeContainer,) repeated_scalar_types += (_message.RepeatedScalarContainer,) - # For compatibility with protobuf 5.x, - # we'll fall back to `map_composite_type_names` to check whether - # the name of the class of a protobuf type is - # `MessageMapContainer`, and, if `True`, return a MapComposite. - # See https://github.com/protocolbuffers/protobuf/issues/16596 - map_composite_type_names = ("MessageMapContainer",) - try: map_composite_types += (_message.MessageMapContainer,) except: From 13998e7c0d0ab786dacac49b74d47f62043a9284 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Thu, 11 Jul 2024 19:01:54 +0000 Subject: [PATCH 4/5] restore comment --- proto/marshal/compat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proto/marshal/compat.py b/proto/marshal/compat.py index 742a8fdb..2f85dafa 100644 --- a/proto/marshal/compat.py +++ b/proto/marshal/compat.py @@ -37,8 +37,8 @@ repeated_scalar_types = (containers.RepeatedScalarFieldContainer,) map_composite_types = (containers.MessageMap,) -# For compatibility with protobuf 5.x, -# we'll fall back to `map_composite_type_names` to check whether +# In `proto/marshal.py`, for compatibility with protobuf 5.x, +# we'll use `map_composite_type_names` to check whether # the name of the class of a protobuf type is # `MessageMapContainer`, and, if `True`, return a MapComposite. # See https://github.com/protocolbuffers/protobuf/issues/16596 From 4cd744c5bb9acffd6e505bbaf71f05a8741b6fb4 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Thu, 11 Jul 2024 19:03:04 +0000 Subject: [PATCH 5/5] catch AttributeError --- proto/marshal/compat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/marshal/compat.py b/proto/marshal/compat.py index 2f85dafa..d1b7c290 100644 --- a/proto/marshal/compat.py +++ b/proto/marshal/compat.py @@ -50,7 +50,7 @@ try: map_composite_types += (_message.MessageMapContainer,) - except: + except AttributeError: # The `MessageMapContainer` attribute is not available in Protobuf 5.x+ pass