diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-02-07 17:55:07 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-02-07 17:55:46 -0500 |
| commit | 47aa62abde6eba67802f2f7126cc79fbd95b5d1a (patch) | |
| tree | 06af970bd57606526d9aa16ef1c1dfa49c87021a /lib/sqlalchemy | |
| parent | 47202abbf9823e1058e0b88ce64ffd3b88027e96 (diff) | |
| download | sqlalchemy-47aa62abde6eba67802f2f7126cc79fbd95b5d1a.tar.gz | |
Vendor inspect.formatannotation
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.
Fixes: #5138
Change-Id: I76bdddc28507fb1b4403f1b718d6f9cc2fb6d93c
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/util/compat.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/sqlalchemy/util/compat.py b/lib/sqlalchemy/util/compat.py index ea9ac0f11..8967955cd 100644 --- a/lib/sqlalchemy/util/compat.py +++ b/lib/sqlalchemy/util/compat.py @@ -270,7 +270,18 @@ else: 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, @@ -285,7 +296,7 @@ if py35: 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. |
