summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrazer McLean <frazer@frazermclean.co.uk>2016-07-26 00:02:03 +0200
committerFrazer McLean <frazer@frazermclean.co.uk>2016-08-06 02:25:27 +0100
commit87d5982e582f2439e6d6fad8b38d9f2122811f1c (patch)
tree5142c6617431ee1af688cb3cdae83f0c2f4cbdb4
parentf2fa9d000b44a54b0fd3ae6114eb5d53ef20c3b8 (diff)
downloadsqlalchemy-87d5982e582f2439e6d6fad8b38d9f2122811f1c.tar.gz
Add docstring to declarative_base
Change-Id: I5ad44362515908592f1e8b1e6254a5270d43234a Pull-request: https://github.com/zzzeek/sqlalchemy/pull/295
-rw-r--r--doc/build/changelog/changelog_11.rst8
-rw-r--r--lib/sqlalchemy/ext/declarative/api.py6
-rw-r--r--test/ext/declarative/test_basic.py9
3 files changed, 23 insertions, 0 deletions
diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst
index b94104be8..e08976f15 100644
--- a/doc/build/changelog/changelog_11.rst
+++ b/doc/build/changelog/changelog_11.rst
@@ -63,6 +63,14 @@
exists in 1.0.x as well, however in 1.1 is more noticeable as
hybrid_property @expression now returns a wrapped element.
+ .. change::
+ :tags: change, orm, declarative
+
+ Constructing a declarative base class that inherits from another class
+ will also inherit its docstring. This means
+ :func:`~.ext.declarative.as_declarative` acts more like a normal class
+ decorator.
+
.. changelog::
:version: 1.1.0b3
:released: July 26, 2016
diff --git a/lib/sqlalchemy/ext/declarative/api.py b/lib/sqlalchemy/ext/declarative/api.py
index e67e79d55..1abd0467e 100644
--- a/lib/sqlalchemy/ext/declarative/api.py
+++ b/lib/sqlalchemy/ext/declarative/api.py
@@ -301,6 +301,9 @@ def declarative_base(bind=None, metadata=None, mapper=None, cls=object,
compatible callable to use as the meta type of the generated
declarative base class.
+ .. versionchanged:: 1.1 if :paramref:`.declarative_base.cls` is a single class (rather
+ than a tuple), the constructed base class will inherit its docstring.
+
.. seealso::
:func:`.as_declarative`
@@ -317,6 +320,9 @@ def declarative_base(bind=None, metadata=None, mapper=None, cls=object,
class_dict = dict(_decl_class_registry=class_registry,
metadata=lcl_metadata)
+ if isinstance(cls, type):
+ class_dict['__doc__'] = cls.__doc__
+
if constructor:
class_dict['__init__'] = constructor
if mapper:
diff --git a/test/ext/declarative/test_basic.py b/test/ext/declarative/test_basic.py
index ae1a85f8b..67018d737 100644
--- a/test/ext/declarative/test_basic.py
+++ b/test/ext/declarative/test_basic.py
@@ -1722,6 +1722,15 @@ class DeclarativeTest(DeclarativeTestBase):
]
)
+ def test_cls_docstring(self):
+
+ class MyBase(object):
+ """MyBase Docstring"""
+
+ Base = decl.declarative_base(cls=MyBase)
+
+ eq_(Base.__doc__, MyBase.__doc__)
+
def _produce_test(inline, stringbased):