From: Mike Bayer Date: Sun, 4 Jul 2010 16:06:19 +0000 (-0400) Subject: transfer docstrings from @classproperty to props X-Git-Tag: rel_0_6_2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d6614c63b20aa47d588dcb103672a29e62057bff;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git transfer docstrings from @classproperty to props --- diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index d0a02381d3..e61c33b5a5 100755 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -840,7 +840,11 @@ def _as_declarative(cls, classname, dict_): "be declared as @classproperty callables " "on declarative mixin classes.") elif isinstance(obj, util.classproperty): - dict_[name] = column_copies[obj] = getattr(cls, name) + dict_[name] = ret = \ + column_copies[obj] = getattr(cls, name) + if isinstance(ret, (Column, MapperProperty)) and \ + ret.doc is None: + ret.doc = obj.__doc__ # apply inherited columns as we should for k, v in potential_columns.items(): diff --git a/test/ext/test_declarative.py b/test/ext/test_declarative.py index 1aafc54691..5e5c380735 100644 --- a/test/ext/test_declarative.py +++ b/test/ext/test_declarative.py @@ -2512,6 +2512,39 @@ class DeclarativeMixinPropertyTest(DeclarativeTestBase): filter(MyOtherModel.prop_hoho=='bar').one(), m2 ) + + def test_doc(self): + """test documentation transfer. + + the documentation situation with @classproperty is + problematic. at least see if mapped subclasses + get the doc. + + """ + + class MyMixin(object): + @classproperty + def type_(cls): + """this is a document.""" + return Column(String(50)) + + @classproperty + def t2(cls): + """this is another document.""" + return column_property(Column(String(50))) + + class MyModel(Base,MyMixin): + __tablename__='test' + id = Column(Integer, primary_key=True) + compile_mappers() + eq_( + MyModel.type_.__doc__, + 'this is a document.' + ) + eq_( + MyModel.t2.__doc__, + 'this is another document.' + ) def test_column_in_mapper_args(self): class MyMixin(object): @@ -2602,6 +2635,8 @@ class DeclarativeMixinPropertyTest(DeclarativeTestBase): sess.expire_all() eq_(f1.target, t1) + + def test_relationship(self): self._test_relationship(False)