diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-02-18 23:45:21 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-02-18 23:45:21 -0500 |
commit | 98459628a6c4420492ebe643e633a74ef16d0f04 (patch) | |
tree | 63ff914beb5623abcd3d5dffa0d7ca908f41db56 | |
parent | ce3a4cf62ab3ea2fd962f5ef5928972bd6c79fab (diff) | |
download | sqlalchemy-pr238.tar.gz |
if doc not present
-rw-r--r-- | lib/sqlalchemy/ext/hybrid.py | 4 | ||||
-rw-r--r-- | test/ext/test_hybrid.py | 12 |
2 files changed, 15 insertions, 1 deletions
diff --git a/lib/sqlalchemy/ext/hybrid.py b/lib/sqlalchemy/ext/hybrid.py index 883cbaec7..61181297a 100644 --- a/lib/sqlalchemy/ext/hybrid.py +++ b/lib/sqlalchemy/ext/hybrid.py @@ -687,7 +687,7 @@ class hybrid_method(interfaces.InspectionAttrInfo): """ self.func = func - self.expr = expr or func + self.expression(expr or func) def __get__(self, instance, owner): if instance is None: @@ -700,6 +700,8 @@ class hybrid_method(interfaces.InspectionAttrInfo): SQL-expression producing method.""" self.expr = expr + if not self.expr.__doc__: + self.expr.__doc__ = self.func.__doc__ return self diff --git a/test/ext/test_hybrid.py b/test/ext/test_hybrid.py index 9e103d1e5..82cf1f82c 100644 --- a/test/ext/test_hybrid.py +++ b/test/ext/test_hybrid.py @@ -286,6 +286,15 @@ class MethodExpressionTest(fixtures.TestBase, AssertsCompiledSQL): "This is a class-level docstring" return func.foo(cls._value, value) + value + @hybrid.hybrid_method + def other_value(self, x): + "This is an instance-level docstring" + return int(self._value) + x + + @other_value.expression + def other_value(cls, value): + return func.foo(cls._value, value) + value + return A def test_call(self): @@ -353,12 +362,15 @@ class MethodExpressionTest(fixtures.TestBase, AssertsCompiledSQL): def test_docstring(self): A = self._fixture() eq_(A.value.__doc__, "This is a class-level docstring") + eq_(A.other_value.__doc__, "This is an instance-level docstring") a1 = A(_value=10) # a1.value is still a method, so it has a # docstring eq_(a1.value.__doc__, "This is an instance-level docstring") + eq_(a1.other_value.__doc__, "This is an instance-level docstring") + class SpecialObjectTest(fixtures.TestBase, AssertsCompiledSQL): """tests against hybrids that return a non-ClauseElement. |