mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
gclient_eval, gclient_utils: Fix Python 3.9 removal of collections members
Various collections module members were removed in Python 3.9 after being deprecated and moved to collections.abc in earlier Python 3 versions.
For accessing these members alias collections_abc as:
* collections.abc on Python 3
* collections on Python 2
Traceback (most recent call last):
File "C:\Google\depot_tools\gclient.py", line 107, in <module>
import gclient_eval
File "C:\Google\depot_tools\gclient_eval.py", line 11, in <module>
import gclient_utils
File "C:\Google\depot_tools\gclient_utils.py", line 1201, in <module>
class FrozenDict(collections.Mapping):
AttributeError: module 'collections' has no attribute 'Mapping'
Traceback (most recent call last):
File "C:\Google\depot_tools\gclient.py", line 107, in <module>
import gclient_eval
File "C:\Google\depot_tools\gclient_eval.py", line 25, in <module>
class _NodeDict(collections.MutableMapping):
AttributeError: module 'collections' has no attribute 'MutableMapping'
Bug: 984182
Change-Id: I7a4417978b93e29397e63764e4570a598c075bc0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2043879
Auto-Submit: Raul Tambre <raul@tambre.ee>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
This commit is contained in:
@@ -28,9 +28,11 @@ import subprocess2
|
||||
|
||||
if sys.version_info.major == 2:
|
||||
from cStringIO import StringIO
|
||||
import collections as collections_abc
|
||||
import Queue as queue
|
||||
import urlparse
|
||||
else:
|
||||
from collections import abc as collections_abc
|
||||
from io import StringIO
|
||||
import queue
|
||||
import urllib.parse as urlparse
|
||||
@@ -1187,7 +1189,7 @@ def freeze(obj):
|
||||
|
||||
Will raise TypeError if you pass an object which is not hashable.
|
||||
"""
|
||||
if isinstance(obj, collections.Mapping):
|
||||
if isinstance(obj, collections_abc.Mapping):
|
||||
return FrozenDict((freeze(k), freeze(v)) for k, v in obj.items())
|
||||
elif isinstance(obj, (list, tuple)):
|
||||
return tuple(freeze(i) for i in obj)
|
||||
@@ -1198,7 +1200,7 @@ def freeze(obj):
|
||||
return obj
|
||||
|
||||
|
||||
class FrozenDict(collections.Mapping):
|
||||
class FrozenDict(collections_abc.Mapping):
|
||||
"""An immutable OrderedDict.
|
||||
|
||||
Modified From: http://stackoverflow.com/a/2704866
|
||||
@@ -1212,7 +1214,7 @@ class FrozenDict(collections.Mapping):
|
||||
operator.xor, (hash(i) for i in enumerate(self._d.items())), 0)
|
||||
|
||||
def __eq__(self, other):
|
||||
if not isinstance(other, collections.Mapping):
|
||||
if not isinstance(other, collections_abc.Mapping):
|
||||
return NotImplemented
|
||||
if self is other:
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user