diff options
| author | Nathaniel Knight <nknight@cfenet.ubc.ca> | 2018-07-31 21:59:47 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-08-01 12:30:09 -0400 |
| commit | a51b0528d3dca59e655e4d19b50bb271015f8196 (patch) | |
| tree | 5a50c4981c5dbd71e4a0a4cbde252b8571d4f180 /lib/sqlalchemy | |
| parent | 1c32206120b1a6555f8bb7a20a0c4c53ea2f52a8 (diff) | |
| download | sqlalchemy-a51b0528d3dca59e655e4d19b50bb271015f8196.tar.gz | |
Fix collections ABC access before Python 3.8
Started importing "collections" from "collections.abc" under Python 3.3 and
greater for Python 3.8 compatibility. Pull request courtesy Nathaniel
Knight.
In Python 3.3, the abstract base classes (Iterable, Mapping, etc.)
were moved from the `collections` module and put in the
`collections.abc` module. They remain in the `collections` module for
backwards compatibility, and will until Python 3.8.
This commit adds a variable (`collections_abc`) to the `util/compat`
module, which will be the `collections` module for Python < 3.3 and
before, or the `collections.abc` module for Python >= 3.3. It also
uses the new variable, getting rid of some deprecation warnings that
were seen when running under Python 3.7.
Change-Id: I2d1c0ef97c8ecac7af152cc56263422a40faa6bb
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/464
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/util/__init__.py | 2 | ||||
| -rw-r--r-- | lib/sqlalchemy/util/_collections.py | 6 | ||||
| -rw-r--r-- | lib/sqlalchemy/util/compat.py | 9 |
3 files changed, 13 insertions, 4 deletions
diff --git a/lib/sqlalchemy/util/__init__.py b/lib/sqlalchemy/util/__init__.py index 2a2d5cfc6..031376d78 100644 --- a/lib/sqlalchemy/util/__init__.py +++ b/lib/sqlalchemy/util/__init__.py @@ -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, \ diff --git a/lib/sqlalchemy/util/_collections.py b/lib/sqlalchemy/util/_collections.py index cc084a7c7..d8e389c61 100644 --- a/lib/sqlalchemy/util/_collections.py +++ b/lib/sqlalchemy/util/_collections.py @@ -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() @@ -795,7 +795,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): diff --git a/lib/sqlalchemy/util/compat.py b/lib/sqlalchemy/util/compat.py index bc0c3e6e0..02be2b3b9 100644 --- a/lib/sqlalchemy/util/compat.py +++ b/lib/sqlalchemy/util/compat.py @@ -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 + |
