--- /dev/null
+.. change::
+ :tags: bug, installation
+ :tickets: 5138
+
+ Vendored the ``inspect.formatannotation`` function inside of
+ ``sqlalchemy.util.compat``, which is needed for the vendored version of
+ ``inspect.formatargspec``. The function is not documented in cPython and
+ is not guaranteed to be available in future Python versions.
+
if py35:
- from inspect import formatannotation
+
+ def _formatannotation(annotation, base_module=None):
+ """vendored from python 3.7
+ """
+
+ if getattr(annotation, "__module__", None) == "typing":
+ return repr(annotation).replace("typing.", "")
+ if isinstance(annotation, type):
+ if annotation.__module__ in ("builtins", base_module):
+ return annotation.__qualname__
+ return annotation.__module__ + "." + annotation.__qualname__
+ return repr(annotation)
def inspect_formatargspec(
args,
formatvarkw=lambda name: "**" + name,
formatvalue=lambda value: "=" + repr(value),
formatreturns=lambda text: " -> " + text,
- formatannotation=formatannotation,
+ formatannotation=_formatannotation,
):
"""Copy formatargspec from python 3.7 standard library.