diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-01-11 10:12:12 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-01-13 10:57:41 -0500 |
| commit | fa6dd376bb24845724287d980a98ea50eb1cfab1 (patch) | |
| tree | 91e536c76f4b76b8997b02f5cd5a41de29dc90ef /lib/sqlalchemy/util | |
| parent | c703b9ce89483b6f44b97d1fbf56f8df8b14305a (diff) | |
| download | sqlalchemy-fa6dd376bb24845724287d980a98ea50eb1cfab1.tar.gz | |
Support python3.6
Corrects some warnings and adds tox config. Adds DeprecationWarning
to the error category. Large sweep for string literals w/ backslashes
as this is common in docstrings
Co-authored-by: Andrii Soldatenko
Fixes: #3886
Change-Id: Ia7c838dfbbe70b262622ed0803d581edc736e085
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/337
Diffstat (limited to 'lib/sqlalchemy/util')
| -rw-r--r-- | lib/sqlalchemy/util/compat.py | 66 | ||||
| -rw-r--r-- | lib/sqlalchemy/util/langhelpers.py | 4 |
2 files changed, 37 insertions, 33 deletions
diff --git a/lib/sqlalchemy/util/compat.py b/lib/sqlalchemy/util/compat.py index beffc8541..5c615b0bc 100644 --- a/lib/sqlalchemy/util/compat.py +++ b/lib/sqlalchemy/util/compat.py @@ -8,6 +8,7 @@ """Handle Python version/platform incompatibilities.""" import sys +from contextlib import contextmanager try: import threading @@ -231,35 +232,38 @@ def with_metaclass(meta, *bases): return metaclass('temporary_class', None, {}) -from contextlib import contextmanager -try: - from contextlib import nested -except ImportError: - # removed in py3k, credit to mitsuhiko for - # workaround - - @contextmanager - def nested(*managers): - exits = [] - vars = [] - exc = (None, None, None) - try: - for mgr in managers: - exit = mgr.__exit__ - enter = mgr.__enter__ - vars.append(enter()) - exits.append(exit) - yield vars - except: - exc = sys.exc_info() - finally: - while exits: - exit = exits.pop() - try: - if exit(*exc): - exc = (None, None, None) - except: - exc = sys.exc_info() - if exc != (None, None, None): - reraise(exc[0], exc[1], exc[2]) + +@contextmanager +def nested(*managers): + """Implement contextlib.nested, mostly for unit tests. + + As tests still need to run on py2.6 we can't use multiple-with yet. + + Function is removed in py3k but also emits deprecation warning in 2.7 + so just roll it here for everyone. + + """ + + exits = [] + vars = [] + exc = (None, None, None) + try: + for mgr in managers: + exit = mgr.__exit__ + enter = mgr.__enter__ + vars.append(enter()) + exits.append(exit) + yield vars + except: + exc = sys.exc_info() + finally: + while exits: + exit = exits.pop() + try: + if exit(*exc): + exc = (None, None, None) + except: + exc = sys.exc_info() + if exc != (None, None, None): + reraise(exc[0], exc[1], exc[2]) diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py index 00572fca8..973de426c 100644 --- a/lib/sqlalchemy/util/langhelpers.py +++ b/lib/sqlalchemy/util/langhelpers.py @@ -221,7 +221,7 @@ class PluginLoader(object): def get_cls_kwargs(cls, _set=None): - """Return the full set of inherited kwargs for the given `cls`. + r"""Return the full set of inherited kwargs for the given `cls`. Probes a class's __init__ method, collecting all named arguments. If the __init__ defines a \**kwargs catch-all, then the constructor is presumed @@ -1006,7 +1006,7 @@ def asint(value): def coerce_kw_type(kw, key, type_, flexi_bool=True): - """If 'key' is present in dict 'kw', coerce its value to type 'type\_' if + r"""If 'key' is present in dict 'kw', coerce its value to type 'type\_' if necessary. If 'flexi_bool' is True, the string '0' is considered false when coercing to boolean. """ |
