From 1582b963f1bc63501df2f10669e2c73e3e8f26cf Mon Sep 17 00:00:00 2001 From: "Dennis E. Mungai" Date: Wed, 15 Mar 2023 04:17:32 +0300 Subject: [PATCH] -Fix: Python 3.10= issues with `collections.abc` This issue is observed on Python 3.10+ and above. This workaround addresses a major backwards compatibility break with a major Python release version where collections.abc isn't available. --- .../python/google/protobuf/internal/containers.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packager/third_party/protobuf/python/google/protobuf/internal/containers.py b/packager/third_party/protobuf/python/google/protobuf/internal/containers.py index 68be9e54a8d..8727194267e 100755 --- a/packager/third_party/protobuf/python/google/protobuf/internal/containers.py +++ b/packager/third_party/protobuf/python/google/protobuf/internal/containers.py @@ -42,8 +42,15 @@ __author__ = 'petar@google.com (Petar Petrov)' import collections + +try: + packagerCor = collections.abc +except AttributeError: + packagerCor = collections + import sys + if sys.version_info[0] < 3: # We would use collections.MutableMapping all the time, but in Python 2 it # doesn't define __slots__. This causes two significant problems: @@ -179,7 +186,7 @@ def setdefault(self, key, default=None): else: # In Python 3 we can just use MutableMapping directly, because it defines # __slots__. - MutableMapping = collections.MutableMapping + MutableMapping = packagerCor.MutableMapping class BaseContainer(object): @@ -337,7 +344,7 @@ def __eq__(self, other): # We are presumably comparing against some other sequence type. return other == self._values -collections.MutableSequence.register(BaseContainer) +packagerCor.MutableSequence.register(BaseContainer) class RepeatedCompositeFieldContainer(BaseContainer):