]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Clean up all Python 3.6 warnings
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 11 Oct 2017 21:17:19 +0000 (17:17 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 11 Oct 2017 23:48:58 +0000 (19:48 -0400)
Fixed a few Python3.6 deprecation warnings by replacing ``StopIteration``
with ``return``, as well as using ``getfullargspec()`` instead of
``getargspec()`` under Python 3.

Additionally fixed docstrings with backslashes needing r'', filehandles
not explicitly closed, accommodate for .pyc files not necessarily present.

Change-Id: Id9791c5fa8b4b1f3e4e36f237a8a8ebcef4aaaba
Fixes: #458
14 files changed:
alembic/config.py
alembic/operations/base.py
alembic/operations/ops.py
alembic/runtime/environment.py
alembic/runtime/migration.py
alembic/script/revision.py
alembic/testing/exclusions.py
alembic/testing/fixtures.py
alembic/testing/plugin/plugin_base.py
alembic/util/compat.py
alembic/util/langhelpers.py
docs/build/unreleased/458.rst [new file with mode: 0644]
tests/test_script_consumption.py
tests/test_script_production.py

index 3774cd32919d6ee1dfc7824802f417921b75f336..46ccb91a4e76db63da207b63afca8a51b7264836 100644 (file)
@@ -432,7 +432,7 @@ class CommandLine(object):
                     fn.__name__[0] != '_' and \
                     fn.__module__ == 'alembic.command':
 
-                spec = inspect.getargspec(fn)
+                spec = compat.inspect_getargspec(fn)
                 if spec[3]:
                     positional = spec[0][1:-len(spec[3])]
                     kwarg = spec[0][-len(spec[3]):]
index 22d601de99fe9dc84bce18ced6813035087fd862..ef6ecf8ff476fce0cbe71c7bc3060d67ba6784a8 100644 (file)
@@ -5,6 +5,7 @@ from ..util import sqla_compat
 from . import batch
 from . import schemaobj
 from ..util.compat import exec_
+from ..util.compat import inspect_getargspec
 import textwrap
 import inspect
 
@@ -91,7 +92,7 @@ class Operations(util.ModuleClsProxy):
                 fn = getattr(op_cls, sourcename)
                 source_name = fn.__name__
 
-            spec = inspect.getargspec(fn)
+            spec = inspect_getargspec(fn)
 
             name_args = spec[0]
             assert name_args[0:2] == ['cls', 'operations']
index 64a508e3b9b97c4e46d13886bfe5246e5d7b5614..43001fedc85ebc74fb7392c8ef91497833508133 100644 (file)
@@ -794,7 +794,7 @@ class CreateIndexOp(MigrateOperation):
             cls, operations,
             index_name, table_name, columns, schema=None,
             unique=False, **kw):
-        """Issue a "create index" instruction using the current
+        r"""Issue a "create index" instruction using the current
         migration context.
 
         e.g.::
@@ -927,7 +927,7 @@ class DropIndexOp(MigrateOperation):
     ])
     def drop_index(cls, operations, index_name,
                    table_name=None, schema=None, **kw):
-        """Issue a "drop index" instruction using the current
+        r"""Issue a "drop index" instruction using the current
         migration context.
 
         e.g.::
@@ -1027,7 +1027,7 @@ class CreateTableOp(MigrateOperation):
     @classmethod
     @util._with_legacy_names([('name', 'table_name')])
     def create_table(cls, operations, table_name, *columns, **kw):
-        """Issue a "create table" instruction using the current migration
+        r"""Issue a "create table" instruction using the current migration
         context.
 
         This directive receives an argument list similar to that of the
@@ -1157,7 +1157,7 @@ class DropTableOp(MigrateOperation):
     @classmethod
     @util._with_legacy_names([('name', 'table_name')])
     def drop_table(cls, operations, table_name, schema=None, **kw):
-        """Issue a "drop table" instruction using the current
+        r"""Issue a "drop table" instruction using the current
         migration context.
 
 
index 613b7459841c348a2a8b562095cd32894ada3c2f..ce9be63785e648663003678f767cc06194fe1920 100644 (file)
@@ -81,7 +81,7 @@ class EnvironmentContext(util.ModuleClsProxy):
     """
 
     def __init__(self, config, script, **kw):
-        """Construct a new :class:`.EnvironmentContext`.
+        r"""Construct a new :class:`.EnvironmentContext`.
 
         :param config: a :class:`.Config` instance.
         :param script: a :class:`.ScriptDirectory` instance.
index 65b4855d634b7e0ca078831d5b06cdda4c3c3b18..17cc2265438be65600b42e83e0f6028955b8a588 100644 (file)
@@ -287,7 +287,7 @@ class MigrationContext(object):
             head_maintainer.update_to_step(step)
 
     def run_migrations(self, **kw):
-        """Run the migration scripts established for this
+        r"""Run the migration scripts established for this
         :class:`.MigrationContext`, if any.
 
         The commands in :mod:`alembic.command` will set up a function
index 1e68a7c3c4abe4997f1c91b0ff8c05a532881a39..3d9a332de59684726fefab4e898ebcc15bf3b7ef 100644 (file)
@@ -656,7 +656,7 @@ class RevisionMap(object):
         uppers = util.dedupe_tuple(self.get_revisions(upper))
 
         if not uppers and not requested_lowers:
-            raise StopIteration()
+            return
 
         upper_ancestors = set(self._get_ancestor_nodes(uppers, check=True))
 
@@ -716,7 +716,7 @@ class RevisionMap(object):
             # if the requested start is one of those branch points,
             # then just return empty set
             if start_from.intersection(upper_ancestors):
-                raise StopIteration()
+                return
             else:
                 # otherwise, they requested nodes out of
                 # order
index 75348d4e257db38ed4103b20dd0681c378517d29..7d33a5b3f20e25fecb1b3a9d6bcda91307a3d0fc 100644 (file)
@@ -302,7 +302,7 @@ class SpecPredicate(Predicate):
 
 class LambdaPredicate(Predicate):
     def __init__(self, lambda_, description=None, args=None, kw=None):
-        spec = inspect.getargspec(lambda_)
+        spec = compat.inspect_getargspec(lambda_)
         if not spec[0]:
             self.lambda_ = lambda db: lambda_()
         else:
index b13edaeb68b873b17560106de0dde2b6d10c283d..e6c16dd59c94c8caa4894fb7b68def354d012158 100644 (file)
@@ -111,7 +111,7 @@ def op_fixture(
                 # the impl produces soft tabs,
                 # so search for blocks of 4 spaces
                 msg = re.sub(r'    ', '', msg)
-                msg = re.sub('\;\n*$', '', msg)
+                msg = re.sub(r'\;\n*$', '', msg)
 
             self.lines.append(msg)
 
index 0ed8f847faf9805359598c6e7a03d08e6806e17f..83b30e3823ee82706304d012b8fe9406eae6be4f 100644 (file)
@@ -420,11 +420,10 @@ def generate_sub_tests(cls, module):
             # pytest junit plugin, which is tripped up by the brackets
             # and periods, so sanitize
 
-            alpha_name = re.sub('[_\[\]\.]+', '_', cfg.name)
+            alpha_name = re.sub(r'[_\[\]\.]+', '_', cfg.name)
             alpha_name = re.sub('_+$', '', alpha_name)
             name = "%s_%s" % (cls.__name__, alpha_name)
 
-
             subcls = type(
                 name,
                 (cls, ),
index 4d7e6fadcd359d912453a1690b4823b0f0b50edd..a754f2a8a23cdf6b09caa94cae2a8525c7fb1e3c 100644 (file)
@@ -48,6 +48,21 @@ else:
 
     range = xrange
 
+if py3k:
+    import collections
+    ArgSpec = collections.namedtuple(
+        "ArgSpec",
+        ["args", "varargs", "keywords", "defaults"])
+
+    from inspect import getfullargspec as inspect_getfullargspec
+
+    def inspect_getargspec(func):
+        return ArgSpec(
+            *inspect_getfullargspec(func)[0:4]
+        )
+else:
+    from inspect import getargspec as inspect_getargspec  # noqa
+
 if py3k:
     from configparser import ConfigParser as SafeConfigParser
     import configparser
index a556e943943622c5bd2fb8bcf7fe4351b3984558..aa016f04e2497dc37254552d99d6ff32df584a52 100644 (file)
@@ -6,8 +6,7 @@ import collections
 
 from .compat import callable, exec_, string_types, with_metaclass
 
-from sqlalchemy.util import format_argspec_plus, update_wrapper
-from sqlalchemy.util.compat import inspect_getfullargspec
+from .compat import inspect_getargspec
 
 
 class _ModuleClsMeta(type):
@@ -73,7 +72,7 @@ class ModuleClsProxy(with_metaclass(_ModuleClsMeta)):
     @classmethod
     def _create_method_proxy(cls, name, globals_, locals_):
         fn = getattr(cls, name)
-        spec = inspect.getargspec(fn)
+        spec = inspect_getargspec(fn)
         if spec[0] and spec[0][0] == 'self':
             spec[0].pop(0)
         args = inspect.formatargspec(*spec)
diff --git a/docs/build/unreleased/458.rst b/docs/build/unreleased/458.rst
new file mode 100644 (file)
index 0000000..bbf2da4
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+    :tags: bug, commands
+    :tickets: 458
+
+    Fixed a few Python3.6 deprecation warnings by replacing ``StopIteration``
+    with ``return``, as well as using ``getfullargspec()`` instead of
+    ``getargspec()`` under Python 3.
\ No newline at end of file
index 7a8f0dc352c713d9493a007ed8f824086e4c2b43..b394784b848279ad77ba7ec6b9a1cb218a98c5f7 100644 (file)
@@ -536,7 +536,7 @@ def downgrade():
 
 """)
         pyc_path = util.pyc_file_from_path(path)
-        if os.access(pyc_path, os.F_OK):
+        if pyc_path is not None and os.access(pyc_path, os.F_OK):
             os.unlink(pyc_path)
 
         assert_raises_message(
index 588b9d1ff50eb634541d7d6868f7e9932a1eaa94..7ab46ab6feec23a5251a910b332e387df19bf1ce 100644 (file)
@@ -549,7 +549,8 @@ def downgrade():
                 head="model1@head",
                 process_revision_directives=process_revision_directives)
 
-        result = open(rev.path).read()
+        with open(rev.path) as handle:
+            result = handle.read()
         assert ("""
 def upgrade():
     # ### commands auto generated by Alembic - please adjust! ###
@@ -985,7 +986,8 @@ context.configure(dialect_name='sqlite', template_args={"somearg":"somevalue"})
                 str(ce)
             )
             assert m, "Command error did not produce a file"
-            contents = open(m.group(1)).read()
+            with open(m.group(1)) as handle:
+                contents = handle.read()
             os.remove(m.group(1))
             assert "<% z = x + y %>" in contents