]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Remove formatargspec work from create_method_proxy
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 29 Mar 2019 17:46:32 +0000 (13:46 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 30 Mar 2019 01:14:29 +0000 (21:14 -0400)
Simplified the internal scheme used to generate the ``alembic.op`` namespace
to no longer attempt to generate full method signatures (e.g. rather than
generic ``*args, **kw``) as this was not working in most cases anyway, while
in rare circumstances it would in fact sporadically have access to the real
argument names and then fail when generating the function due to missing
symbols in the argument signature.

Change-Id: I06e4ecf1ddcdb0799856ba7e39b17f28d19cc5d2
Fixes: #548
alembic/util/langhelpers.py
docs/build/unreleased/548.rst [new file with mode: 0644]

index cb44b1fe81a37542bc2a56c395bffc616100e158..bb9c8f534e16e8ece150f8def20a1e7d507e5e0e 100644 (file)
@@ -6,7 +6,6 @@ import warnings
 from .compat import callable
 from .compat import collections_abc
 from .compat import exec_
-from .compat import inspect_formatargspec
 from .compat import inspect_getargspec
 from .compat import string_types
 from .compat import with_metaclass
@@ -74,26 +73,6 @@ class ModuleClsProxy(with_metaclass(_ModuleClsMeta)):
     @classmethod
     def _create_method_proxy(cls, name, globals_, locals_):
         fn = getattr(cls, name)
-        spec = inspect_getargspec(fn)
-        if spec[0] and spec[0][0] == "self":
-            spec[0].pop(0)
-        args = inspect_formatargspec(*spec)
-        num_defaults = 0
-        if spec[3]:
-            num_defaults += len(spec[3])
-        name_args = spec[0]
-        if num_defaults:
-            defaulted_vals = name_args[0 - num_defaults :]
-        else:
-            defaulted_vals = ()
-
-        apply_kw = inspect_formatargspec(
-            name_args,
-            spec[1],
-            spec[2],
-            defaulted_vals,
-            formatvalue=lambda x: "=" + x,
-        )
 
         def _name_error(name):
             raise NameError(
@@ -108,6 +87,10 @@ class ModuleClsProxy(with_metaclass(_ModuleClsMeta)):
 
         translations = getattr(fn, "_legacy_translations", [])
         if translations:
+            spec = inspect_getargspec(fn)
+            if spec[0] and spec[0][0] == "self":
+                spec[0].pop(0)
+
             outer_args = inner_args = "*args, **kw"
             translate_str = "args, kw = _translate(%r, %r, %r, args, kw)" % (
                 fn.__name__,
@@ -148,8 +131,8 @@ class ModuleClsProxy(with_metaclass(_ModuleClsMeta)):
 
             globals_["_translate"] = translate
         else:
-            outer_args = args[1:-1]
-            inner_args = apply_kw[1:-1]
+            outer_args = "*args, **kw"
+            inner_args = "*args, **kw"
             translate_str = ""
 
         func_text = textwrap.dedent(
diff --git a/docs/build/unreleased/548.rst b/docs/build/unreleased/548.rst
new file mode 100644 (file)
index 0000000..87f6798
--- /dev/null
@@ -0,0 +1,10 @@
+.. change::
+   :tags: bug, operations
+   :tickets: 548
+
+   Simplified the internal scheme used to generate the ``alembic.op`` namespace
+   to no longer attempt to generate full method signatures (e.g. rather than
+   generic ``*args, **kw``) as this was not working in most cases anyway, while
+   in rare circumstances it would in fact sporadically have access to the real
+   argument names and then fail when generating the function due to missing
+   symbols in the argument signature.