-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
Open
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
types.DynamicClassAttribute loses an explicitly provided empty docstring. Its constructor assigns self.__doc__ = doc or fget.__doc__, so when you pass doc='' and fget is None, the descriptor ends up with None.__doc__ (“The type of the None singleton.”) instead of retaining the empty string. This breaks parity with property, which preserves an empty doc, and cascades through setter()/deleter().
from types import DynamicClassAttribute
attr = DynamicClassAttribute(fget=None, fset=None, fdel=None, doc='')
print(repr(attr.__doc__)) # Expected '', but prints 'The type of the None singleton.'None
Easy Fix:
class DynamicClassAttribute:
def __init__(self, fget=None, fset=None, fdel=None, doc=None):
self.fget = fget
self.fset = fset
self.fdel = fdel
- self.__doc__ = doc or fget.__doc__
- self.overwrite_doc = doc is None
+ if doc is None and fget is not None:
+ doc = fget.__doc__
+ self.__doc__ = doc
+ self.overwrite_doc = doc is NoneCPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error