From 89733801bf541e7b8f7bbd834006446ba6acfe38 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Thu, 18 Feb 2016 00:11:56 -0500 Subject: Proxy docstring along to hybrid_property and hybrid_method --- lib/sqlalchemy/ext/hybrid.py | 5 ++++- test/ext/test_hybrid.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/sqlalchemy/ext/hybrid.py b/lib/sqlalchemy/ext/hybrid.py index bbf386742..22296c3de 100644 --- a/lib/sqlalchemy/ext/hybrid.py +++ b/lib/sqlalchemy/ext/hybrid.py @@ -784,7 +784,10 @@ class hybrid_property(interfaces.InspectionAttrInfo): create_proxied_attribute(self) def expr(owner): - return proxy_attr(owner, self.__name__, self, comparator(owner)) + return proxy_attr( + owner, self.__name__, self, comparator(owner), + doc=self.__doc__, + ) self.expr = expr return self diff --git a/test/ext/test_hybrid.py b/test/ext/test_hybrid.py index e36b8f7e9..744789c3c 100644 --- a/test/ext/test_hybrid.py +++ b/test/ext/test_hybrid.py @@ -30,6 +30,7 @@ class PropertyComparatorTest(fixtures.TestBase, AssertsCompiledSQL): @hybrid.hybrid_property def value(self): + "This is a docstring" return self._value - 5 @value.comparator @@ -81,6 +82,11 @@ class PropertyComparatorTest(fixtures.TestBase, AssertsCompiledSQL): "FROM a AS a_1 WHERE upper(a_1.value) = upper(:upper_1)" ) + def test_docstring(self): + A = self._fixture() + eq_(A.value.__doc__, "This is a docstring") + + class PropertyExpressionTest(fixtures.TestBase, AssertsCompiledSQL): __dialect__ = 'default' def _fixture(self): @@ -257,10 +263,12 @@ class MethodExpressionTest(fixtures.TestBase, AssertsCompiledSQL): @hybrid.hybrid_method def value(self, x): + "This is an instance-level docstring" return int(self._value) + x @value.expression def value(cls, value): + "This is a class-level docstring" return func.foo(cls._value, value) + value return A @@ -327,3 +335,9 @@ class MethodExpressionTest(fixtures.TestBase, AssertsCompiledSQL): sess.query(aliased(A).value(5)), "SELECT foo(a_1.value, :foo_1) + :foo_2 AS anon_1 FROM a AS a_1" ) + + def test_docstring(self): + A = self._fixture() + eq_(A.value.__doc__, "This is a class-level docstring") + a1 = A(_value=10) + eq_(a1.value.__doc__, "This is an instance-level docstring") -- cgit v1.2.1