diff options
author | David Baumgold <david@davidbaumgold.com> | 2016-02-18 00:11:56 -0500 |
---|---|---|
committer | David Baumgold <david@davidbaumgold.com> | 2016-02-18 00:18:34 -0500 |
commit | 89733801bf541e7b8f7bbd834006446ba6acfe38 (patch) | |
tree | 122d72afe074a88029d88743d4592db361321117 | |
parent | 594a974ede97941a61c2e657a63cb11a7137c1ae (diff) | |
download | sqlalchemy-pr/238.tar.gz |
Proxy docstring along to hybrid_property and hybrid_methodpr/238
-rw-r--r-- | lib/sqlalchemy/ext/hybrid.py | 5 | ||||
-rw-r--r-- | test/ext/test_hybrid.py | 14 |
2 files changed, 18 insertions, 1 deletions
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") |