diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2016-08-22 10:49:48 -0400 |
---|---|---|
committer | Gerrit Code Review <gerrit2@ln3.zzzcomputing.com> | 2016-08-22 10:49:48 -0400 |
commit | f10eba00ea7c92315b4b39c69627058ad4931448 (patch) | |
tree | 0018552b6b0c3a1aaafb147fbca88e74b0f14867 | |
parent | 5145f671a4b5eb072e996bc450d2946d4be2a343 (diff) | |
parent | 87d5982e582f2439e6d6fad8b38d9f2122811f1c (diff) | |
download | sqlalchemy-f10eba00ea7c92315b4b39c69627058ad4931448.tar.gz |
Merge "Add docstring to declarative_base"
-rw-r--r-- | doc/build/changelog/changelog_11.rst | 8 | ||||
-rw-r--r-- | lib/sqlalchemy/ext/declarative/api.py | 6 | ||||
-rw-r--r-- | test/ext/declarative/test_basic.py | 9 |
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): |