mirror of https://github.com/python/cpython
Fix imports from collections.abc
This commit is contained in:
parent
bd475115c4
commit
57d1a887e7
|
@ -119,7 +119,8 @@ ConfigParser -- responsible for parsing a list of
|
||||||
between keys and values are surrounded by spaces.
|
between keys and values are surrounded by spaces.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from collections import MutableMapping, OrderedDict as _default_dict, _ChainMap
|
from collections.abc import MutableMapping
|
||||||
|
from collections import OrderedDict as _default_dict, _ChainMap
|
||||||
import functools
|
import functools
|
||||||
import io
|
import io
|
||||||
import itertools
|
import itertools
|
||||||
|
|
|
@ -42,7 +42,7 @@ from types import MethodType as _MethodType, BuiltinMethodType as _BuiltinMethod
|
||||||
from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
|
from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
|
||||||
from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin
|
from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin
|
||||||
from os import urandom as _urandom
|
from os import urandom as _urandom
|
||||||
import collections as _collections
|
from collections.abc import Set as _Set, Sequence as _Sequence
|
||||||
from hashlib import sha512 as _sha512
|
from hashlib import sha512 as _sha512
|
||||||
|
|
||||||
__all__ = ["Random","seed","random","uniform","randint","choice","sample",
|
__all__ = ["Random","seed","random","uniform","randint","choice","sample",
|
||||||
|
@ -293,10 +293,10 @@ class Random(_random.Random):
|
||||||
# preferred since the list takes less space than the
|
# preferred since the list takes less space than the
|
||||||
# set and it doesn't suffer from frequent reselections.
|
# set and it doesn't suffer from frequent reselections.
|
||||||
|
|
||||||
if isinstance(population, _collections.Set):
|
if isinstance(population, _Set):
|
||||||
population = tuple(population)
|
population = tuple(population)
|
||||||
if not isinstance(population, _collections.Sequence):
|
if not isinstance(population, _Sequence):
|
||||||
raise TypeError("Population must be a sequence or Set. For dicts, use list(d).")
|
raise TypeError("Population must be a sequence or set. For dicts, use list(d).")
|
||||||
randbelow = self._randbelow
|
randbelow = self._randbelow
|
||||||
n = len(population)
|
n = len(population)
|
||||||
if not 0 <= k <= n:
|
if not 0 <= k <= n:
|
||||||
|
|
|
@ -15,7 +15,7 @@ import shutil
|
||||||
import warnings
|
import warnings
|
||||||
import unittest
|
import unittest
|
||||||
import importlib
|
import importlib
|
||||||
import collections
|
import collections.abc
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import imp
|
import imp
|
||||||
|
@ -682,7 +682,7 @@ class CleanImport(object):
|
||||||
sys.modules.update(self.original_modules)
|
sys.modules.update(self.original_modules)
|
||||||
|
|
||||||
|
|
||||||
class EnvironmentVarGuard(collections.MutableMapping):
|
class EnvironmentVarGuard(collections.abc.MutableMapping):
|
||||||
|
|
||||||
"""Class to help protect the environment variable properly. Can be used as
|
"""Class to help protect the environment variable properly. Can be used as
|
||||||
a context manager."""
|
a context manager."""
|
||||||
|
|
|
@ -10,12 +10,13 @@ from random import randrange, shuffle
|
||||||
import keyword
|
import keyword
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
from collections import Hashable, Iterable, Iterator
|
from collections import UserDict
|
||||||
from collections import Sized, Container, Callable
|
from collections.abc import Hashable, Iterable, Iterator
|
||||||
from collections import Set, MutableSet
|
from collections.abc import Sized, Container, Callable
|
||||||
from collections import Mapping, MutableMapping, KeysView, ItemsView, UserDict
|
from collections.abc import Set, MutableSet
|
||||||
from collections import Sequence, MutableSequence
|
from collections.abc import Mapping, MutableMapping, KeysView, ItemsView
|
||||||
from collections import ByteString
|
from collections.abc import Sequence, MutableSequence
|
||||||
|
from collections.abc import ByteString
|
||||||
|
|
||||||
TestNT = namedtuple('TestNT', 'x y z') # type used for pickle tests
|
TestNT = namedtuple('TestNT', 'x y z') # type used for pickle tests
|
||||||
|
|
||||||
|
@ -507,7 +508,7 @@ class TestCollectionABCs(ABCTestCase):
|
||||||
|
|
||||||
def test_issue_4920(self):
|
def test_issue_4920(self):
|
||||||
# MutableSet.pop() method did not work
|
# MutableSet.pop() method did not work
|
||||||
class MySet(collections.MutableSet):
|
class MySet(MutableSet):
|
||||||
__slots__=['__s']
|
__slots__=['__s']
|
||||||
def __init__(self,items=None):
|
def __init__(self,items=None):
|
||||||
if items is None:
|
if items is None:
|
||||||
|
@ -553,7 +554,7 @@ class TestCollectionABCs(ABCTestCase):
|
||||||
self.assertTrue(issubclass(sample, Mapping))
|
self.assertTrue(issubclass(sample, Mapping))
|
||||||
self.validate_abstract_methods(Mapping, '__contains__', '__iter__', '__len__',
|
self.validate_abstract_methods(Mapping, '__contains__', '__iter__', '__len__',
|
||||||
'__getitem__')
|
'__getitem__')
|
||||||
class MyMapping(collections.Mapping):
|
class MyMapping(Mapping):
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return 0
|
return 0
|
||||||
def __getitem__(self, i):
|
def __getitem__(self, i):
|
||||||
|
|
|
@ -4,7 +4,7 @@ import textwrap
|
||||||
import unittest
|
import unittest
|
||||||
import functools
|
import functools
|
||||||
import contextlib
|
import contextlib
|
||||||
import collections
|
import collections.abc
|
||||||
from test import support
|
from test import support
|
||||||
from nntplib import NNTP, GroupInfo, _have_ssl
|
from nntplib import NNTP, GroupInfo, _have_ssl
|
||||||
import nntplib
|
import nntplib
|
||||||
|
@ -246,7 +246,7 @@ class NetworkedNNTPTestsMixin:
|
||||||
if not name.startswith('test_'):
|
if not name.startswith('test_'):
|
||||||
continue
|
continue
|
||||||
meth = getattr(cls, name)
|
meth = getattr(cls, name)
|
||||||
if not isinstance(meth, collections.Callable):
|
if not isinstance(meth, collections.abc.Callable):
|
||||||
continue
|
continue
|
||||||
# Need to use a closure so that meth remains bound to its current
|
# Need to use a closure so that meth remains bound to its current
|
||||||
# value
|
# value
|
||||||
|
|
|
@ -2,7 +2,7 @@ import unittest
|
||||||
import shelve
|
import shelve
|
||||||
import glob
|
import glob
|
||||||
from test import support
|
from test import support
|
||||||
from collections import MutableMapping
|
from collections.abc import MutableMapping
|
||||||
from test.test_dbm import dbm_iterator
|
from test.test_dbm import dbm_iterator
|
||||||
|
|
||||||
def L1(s):
|
def L1(s):
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import collections
|
import collections.abc
|
||||||
import errno
|
import errno
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
|
@ -48,7 +48,7 @@ class CurrentTimeTest(unittest.TestCase):
|
||||||
|
|
||||||
# Perform a minimal sanity check on the result, just to be sure
|
# Perform a minimal sanity check on the result, just to be sure
|
||||||
# the request means what we think it means.
|
# the request means what we think it means.
|
||||||
self.assertIsInstance(builders, collections.Sequence)
|
self.assertIsInstance(builders, collections.abc.Sequence)
|
||||||
self.assertTrue([x for x in builders if "3.x" in x], builders)
|
self.assertTrue([x for x in builders if "3.x" in x], builders)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue