summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/util/langhelpers.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-02-08 14:53:21 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2020-02-08 14:53:21 -0500
commit660ff51df0433607b12c58a12c7355107c1773f5 (patch)
tree95c43ce2401ee5aee3d8b3dfa6d241c633d23279 /lib/sqlalchemy/util/langhelpers.py
parent47aa62abde6eba67802f2f7126cc79fbd95b5d1a (diff)
downloadsqlalchemy-660ff51df0433607b12c58a12c7355107c1773f5.tar.gz
Fixes for public_factory and mysql/pg dml functions
* ensure that the location indicated by public_factory is importable * adjust all of sqlalchemy.sql.expression locations to be correct * support the case where a public_factory is against a function that has another public_factory already, and already replaced the __init__ on the target class * Use mysql.insert(), postgresql.insert(), don't include .dml in the class path. Change-Id: Iac285289455d8d7102349df3814f7cedc758e639
Diffstat (limited to 'lib/sqlalchemy/util/langhelpers.py')
-rw-r--r--lib/sqlalchemy/util/langhelpers.py34
1 files changed, 30 insertions, 4 deletions
diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py
index 402f8bb09..41a9698c7 100644
--- a/lib/sqlalchemy/util/langhelpers.py
+++ b/lib/sqlalchemy/util/langhelpers.py
@@ -170,7 +170,7 @@ def _exec_code_in_env(code, env, fn_name):
return env[fn_name]
-def public_factory(target, location):
+def public_factory(target, location, class_location=None):
"""Produce a wrapping function for the given cls or classmethod.
Rationale here is so that the __init__ method of the
@@ -183,14 +183,14 @@ def public_factory(target, location):
doc = (
"Construct a new :class:`.%s` object. \n\n"
"This constructor is mirrored as a public API function; "
- "see :func:`~%s` "
+ "see :func:`sqlalchemy%s` "
"for a full usage and argument description."
% (target.__name__, location)
)
else:
fn = callable_ = target
doc = (
- "This function is mirrored; see :func:`~%s` "
+ "This function is mirrored; see :func:`sqlalchemy%s` "
"for a description of arguments." % location
)
@@ -209,12 +209,38 @@ def %(name)s(%(args)s):
env = {"cls": callable_, "symbol": symbol}
exec(code, env)
decorated = env[location_name]
- decorated.__doc__ = fn.__doc__
+ if hasattr(fn, "_linked_to"):
+ linked_to, linked_to_location = fn._linked_to
+ linked_to_doc = linked_to.__doc__
+ if class_location is None:
+ class_location = "%s.%s" % (target.__module__, target.__name__)
+
+ linked_to_doc = inject_docstring_text(
+ linked_to_doc,
+ ".. container:: inherited_member\n\n "
+ "Inherited from :func:`sqlalchemy%s`; this constructor "
+ "creates a :class:`%s` object"
+ % (linked_to_location, class_location),
+ 0,
+ )
+ decorated.__doc__ = linked_to_doc
+ else:
+ decorated.__doc__ = fn.__doc__
+
decorated.__module__ = "sqlalchemy" + location.rsplit(".", 1)[0]
+ if decorated.__module__ not in sys.modules:
+ raise ImportError(
+ "public_factory location %s is not in sys.modules"
+ % (decorated.__module__,)
+ )
if compat.py2k or hasattr(fn, "__func__"):
fn.__func__.__doc__ = doc
+ if not hasattr(fn.__func__, "_linked_to"):
+ fn.__func__._linked_to = (decorated, location)
else:
fn.__doc__ = doc
+ if not hasattr(fn, "_linked_to"):
+ fn._linked_to = (decorated, location)
return decorated