Python 3.10 support: collections.abc (#20441)

This commit is contained in:
Adam J. Stewart
2021-02-01 11:30:25 -06:00
committed by GitHub
parent f781403615
commit 40a40e0265
19 changed files with 140 additions and 42 deletions

View File

@@ -315,10 +315,14 @@ def __repr__(self):
# register the context as mapping if possible
try:
from collections import Mapping
from collections.abc import Mapping
Mapping.register(Context)
except ImportError:
pass
try:
from collections import Mapping
Mapping.register(Context)
except ImportError:
pass
class BlockReference(object):

View File

@@ -14,7 +14,7 @@
"""
import types
import operator
from collections import Mapping
import sys
from jinja2.environment import Environment
from jinja2.exceptions import SecurityError
from jinja2._compat import string_types, PY2
@@ -23,6 +23,11 @@
from markupsafe import EscapeFormatter
from string import Formatter
if sys.version_info >= (3, 3):
from collections.abc import Mapping
else:
from collections import Mapping
#: maximum number of items a range may produce
MAX_RANGE = 100000
@@ -79,7 +84,10 @@
pass
#: register Python 2.6 abstract base classes
from collections import MutableSet, MutableMapping, MutableSequence
if sys.version_info >= (3, 3):
from collections.abc import MutableSet, MutableMapping, MutableSequence
else:
from collections import MutableSet, MutableMapping, MutableSequence
_mutable_set_types += (MutableSet,)
_mutable_mapping_types += (MutableMapping,)
_mutable_sequence_types += (MutableSequence,)

View File

@@ -10,11 +10,16 @@
"""
import operator
import re
from collections import Mapping
import sys
from jinja2.runtime import Undefined
from jinja2._compat import text_type, string_types, integer_types
import decimal
if sys.version_info >= (3, 3):
from collections.abc import Mapping
else:
from collections import Mapping
number_re = re.compile(r'^-?\d+(\.\d+)?$')
regex_type = type(number_re)

View File

@@ -482,10 +482,14 @@ def __reversed__(self):
# register the LRU cache as mutable mapping if possible
try:
from collections import MutableMapping
from collections.abc import MutableMapping
MutableMapping.register(LRUCache)
except ImportError:
pass
try:
from collections import MutableMapping
MutableMapping.register(LRUCache)
except ImportError:
pass
def select_autoescape(enabled_extensions=('html', 'htm', 'xml'),