`DynamicClassAttribute` drops explicitly provided empty docstrings
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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 None
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
- gh-140975
- gh-141242
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia dal costruttore di DynamicClassAttribute nell’implementazione di types di CPython e verifica come viene gestita una stringa di documentazione vuota fornita esplicitamente quando fget è None. Conferma che il descrittore e i risultati di setter()/deleter() conservino '', in linea con il comportamento di property, e controlla le PR collegate per verificare se ci sono già lavori in corso.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 35/100