-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix issues with
collections.abc
in Python 3.10+ (#1188)
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
1 parent
161947f
commit 80e0240
Showing
1 changed file
with
9 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,8 +42,15 @@ | |
__author__ = '[email protected] (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): | ||
|