diff --git a/proto/marshal/compat.py b/proto/marshal/compat.py index dc77f3ac..d1b7c290 100644 --- a/proto/marshal/compat.py +++ b/proto/marshal/compat.py @@ -19,9 +19,6 @@ # not be included. 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. @@ -51,13 +48,12 @@ 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 - # 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 AttributeError: + # The `MessageMapContainer` attribute is not available in Protobuf 5.x+ + pass + __all__ = ( "repeated_composite_types",