mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-05-28 03:26:01 -04:00
Merge "Fix collections ABC access before Python 3.8"
This commit is contained in:
+6
@@ -0,0 +1,6 @@
|
||||
.. change::
|
||||
:tags: bug, py3k
|
||||
|
||||
Started importing "collections" from "collections.abc" under Python 3.3 and
|
||||
greater for Python 3.8 compatibility. Pull request courtesy Nathaniel
|
||||
Knight.
|
||||
@@ -21,7 +21,7 @@ from ._collections import KeyedTuple, ImmutableContainer, immutabledict, \
|
||||
UniqueAppender, PopulateDict, EMPTY_SET, to_list, to_set, \
|
||||
to_column_set, update_copy, flatten_iterator, has_intersection, \
|
||||
LRUCache, ScopedRegistry, ThreadLocalRegistry, WeakSequence, \
|
||||
coerce_generator_arg, lightweight_named_tuple
|
||||
coerce_generator_arg, lightweight_named_tuple, collections_abc
|
||||
|
||||
from .langhelpers import iterate_attributes, class_hierarchy, \
|
||||
portable_instancemethod, unbound_method_to_callable, \
|
||||
|
||||
@@ -11,10 +11,10 @@ from __future__ import absolute_import
|
||||
import weakref
|
||||
import operator
|
||||
from .compat import threading, itertools_filterfalse, string_types, \
|
||||
binary_types
|
||||
binary_types, collections_abc
|
||||
from . import py2k
|
||||
import types
|
||||
import collections
|
||||
|
||||
|
||||
EMPTY_SET = frozenset()
|
||||
|
||||
@@ -798,7 +798,7 @@ def coerce_generator_arg(arg):
|
||||
def to_list(x, default=None):
|
||||
if x is None:
|
||||
return default
|
||||
if not isinstance(x, collections.Iterable) or \
|
||||
if not isinstance(x, collections_abc.Iterable) or \
|
||||
isinstance(x, string_types + binary_types):
|
||||
return [x]
|
||||
elif isinstance(x, list):
|
||||
|
||||
@@ -327,3 +327,12 @@ def nested(*managers):
|
||||
exc = sys.exc_info()
|
||||
if exc != (None, None, None):
|
||||
reraise(exc[0], exc[1], exc[2])
|
||||
|
||||
|
||||
# Fix deprecation of accessing ABCs straight from collections module
|
||||
# (which will stop working in 3.8).
|
||||
if py33:
|
||||
import collections.abc as collections_abc
|
||||
else:
|
||||
import collections as collections_abc
|
||||
|
||||
|
||||
@@ -636,7 +636,7 @@ class ExtensionOperatorTest(fixtures.TestBase, testing.AssertsCompiledSQL):
|
||||
return self.op("->")(index)
|
||||
|
||||
col = Column('x', MyType())
|
||||
assert not isinstance(col, collections.Iterable)
|
||||
assert not isinstance(col, util.collections_abc.Iterable)
|
||||
|
||||
def test_lshift(self):
|
||||
class MyType(UserDefinedType):
|
||||
|
||||
Reference in New Issue
Block a user