Skip to content

Commit

Permalink
fix: Fix issues with collections.abc in Python 3.10+ (#1188)
Browse files Browse the repository at this point in the history
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.

Fixes #1192
  • Loading branch information
Brainiarc7 committed May 1, 2023
1 parent 161947f commit 80e0240
Showing 1 changed file with 9 additions and 2 deletions.
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 80e0240

Please sign in to comment.