--- /dev/null
+.. change::
+ :tags: bug, orm, py3k
+ :tickets: 4674
+
+ Replaced the Python compatbility routines for ``getfullargspec()`` with a
+ fully vendored version from Python 3.3. Originally, Python was emitting
+ deprecation warnings for this function in Python 3.8 alphas. While this
+ change was reverted, it was observed that Python 3 implementations for
+ ``getfullargspec()`` are an order of magnitude slower as of the 3.4 series
+ where it was rewritten against ``Signature``. While Python plans to
+ improve upon this situation, SQLAlchemy projects for now are using a simple
+ replacement to avoid any future issues.
import collections
import contextlib
+import inspect
import operator
import sys
import time
],
)
-FullArgSpec = collections.namedtuple(
- "FullArgSpec",
- [
- "args",
- "varargs",
- "varkw",
- "defaults",
- "kwonlyargs",
- "kwonlydefaults",
- "annotations",
- ],
-)
-
try:
import threading
except ImportError:
safe_kwarg = str
+def inspect_getfullargspec(func):
+ """Fully vendored version of getfullargspec from Python 3.3."""
+
+ if inspect.ismethod(func):
+ func = func.__func__
+ if not inspect.isfunction(func):
+ raise TypeError("{!r} is not a Python function".format(func))
+
+ co = func.__code__
+ if not inspect.iscode(co):
+ raise TypeError("{!r} is not a code object".format(co))
+
+ nargs = co.co_argcount
+ names = co.co_varnames
+ nkwargs = co.co_kwonlyargcount if py3k else 0
+ args = list(names[:nargs])
+ kwonlyargs = list(names[nargs : nargs + nkwargs])
+ step = 0
+
+ nargs += nkwargs
+ varargs = None
+ if co.co_flags & inspect.CO_VARARGS:
+ varargs = co.co_varnames[nargs]
+ nargs = nargs + 1
+ varkw = None
+ if co.co_flags & inspect.CO_VARKEYWORDS:
+ varkw = co.co_varnames[nargs]
+
+ return FullArgSpec(
+ args,
+ varargs,
+ varkw,
+ func.__defaults__,
+ kwonlyargs,
+ func.__kwdefaults__ if py3k else None,
+ func.__annotations__ if py3k else {},
+ )
+
+
if py3k:
import base64
import builtins
import pickle
from functools import reduce
- from inspect import getfullargspec as inspect_getfullargspec
from io import BytesIO as byte_buffer
from io import StringIO
from itertools import zip_longest
from StringIO import StringIO # noqa
from cStringIO import StringIO as byte_buffer # noqa
- from inspect import getargspec as _getargspec
from itertools import izip_longest as zip_longest # noqa
from urllib import quote # noqa
from urllib import quote_plus # noqa
text_type = unicode # noqa
int_types = int, long # noqa
- def inspect_getfullargspec(func):
- return FullArgSpec(*_getargspec(func)[0:4] + ([], None, {}))
-
callable = callable # noqa
cmp = cmp # noqa
reduce = reduce # noqa