Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Lib/test/test_dynamicclassattribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import abc
import sys
import unittest
from test import support
from types import DynamicClassAttribute

class PropertyBase(Exception):
Expand Down Expand Up @@ -195,6 +196,16 @@ def __init__(self):
Okay2.color
self.assertEqual(Okay2().color, 'magenta')

@support.requires_docstrings
def test_empty_docstring(self):
attr = DynamicClassAttribute(fget=None, fset=None, fdel=None, doc='')
self.assertEqual(attr.__doc__, '')
def fget():
"""fget's docstring"""
attr_with_fget = DynamicClassAttribute(fget=fget, doc='')
self.assertEqual(attr_with_fget.__doc__, '')
attr_no_doc = DynamicClassAttribute(fget=None)
self.assertIsNone(attr_no_doc.__doc__)

# Issue 5890: subclasses of DynamicClassAttribute do not preserve method __doc__ strings
class PropertySub(DynamicClassAttribute):
Expand Down
7 changes: 5 additions & 2 deletions Lib/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,12 @@ def __init__(self, fget=None, fset=None, fdel=None, doc=None):
self.fget = fget
self.fset = fset
self.fdel = fdel
overwrite_doc = doc is None
if doc is None and fget is not None:
doc = fget.__doc__
# next two lines make DynamicClassAttribute act the same as property
self.__doc__ = doc or fget.__doc__
self.overwrite_doc = doc is None
self.__doc__ = doc
self.overwrite_doc = overwrite_doc
# support for abstract methods
self.__isabstractmethod__ = bool(getattr(fget, '__isabstractmethod__', False))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Now empty docstrings passed to :func:`types.DynamicClassAttribute` are
preserved when ``fget`` is ``None``; previously ``NoneType.__doc__`` was used
incorrectly.
Loading