From: Mike Bayer Date: Fri, 29 Mar 2019 17:46:32 +0000 (-0400) Subject: Remove formatargspec work from create_method_proxy X-Git-Tag: rel_1_0_9~1^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3adbb056a7d1fb1da5610c29c9de10009a91873;p=thirdparty%2Fsqlalchemy%2Falembic.git Remove formatargspec work from create_method_proxy 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 --- diff --git a/alembic/util/langhelpers.py b/alembic/util/langhelpers.py index cb44b1fe..bb9c8f53 100644 --- a/alembic/util/langhelpers.py +++ b/alembic/util/langhelpers.py @@ -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 index 00000000..87f6798e --- /dev/null +++ b/docs/build/unreleased/548.rst @@ -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.