2525from types import WrapperDescriptorType
2626from typing import TYPE_CHECKING
2727from typing import Any
28+ from typing import Final
2829
2930from docstring_inheritance .docstring_inheritors .bases .inheritor import (
3031 BaseDocstringInheritor ,
3940class ClassDocstringsInheritor :
4041 """A class for inheriting class docstrings."""
4142
42- _cls : type
43+ __cls : type
4344 """The class to process."""
4445
45- _docstring_inheritor : DocstringInheritorClass
46+ __docstring_inheritor : DocstringInheritorClass
4647 """The docstring inheritor."""
4748
4849 _init_in_class : bool
49- """Whether the `` __init__` ` arguments documentation is in the class docstring."""
50+ """Whether the `__init__` arguments documentation is in the class docstring."""
5051
5152 __mro_classes : list [type ]
5253 """The MRO classes."""
@@ -63,14 +64,14 @@ def __init__(
6364 Args:
6465 cls: The class to process.
6566 docstring_inheritor: The docstring inheritor.
66- init_in_class: Whether the `` __init__` ` arguments documentation is in the
67+ init_in_class: Whether the `__init__` arguments documentation is in the
6768 class docstring.
6869 """ # noqa: D205, D212
6970 # Remove the new class itself and the object class from the mro,
7071 # object's docstrings have no interest.
7172 self .__mro_classes = cls .mro ()[1 :- 1 ]
72- self ._cls = cls
73- self ._docstring_inheritor = docstring_inheritor
73+ self .__cls = cls
74+ self .__docstring_inheritor = docstring_inheritor
7475 self ._init_in_class = init_in_class
7576
7677 @classmethod
@@ -89,31 +90,29 @@ def inherit_docstrings(
8990 class docstring.
9091 """
9192 inheritor = cls (class_ , docstring_inheritor , init_in_class )
92- inheritor ._inherit_attrs_docstrings ()
93- inheritor ._inherit_class_docstring ()
93+ inheritor .__inherit_methods_docstrings ()
94+ inheritor .__inherit_class_docstring ()
9495
95- def _inherit_class_docstring (
96- self ,
97- ) -> None :
96+ def __inherit_class_docstring (self ) -> None :
9897 """Create the inherited docstring for the class docstring."""
9998 func = None
10099 old_init_doc = None
101100 init_doc_changed = False
102101
103102 if self ._init_in_class :
104- init_method : Callable [..., None ] = self ._cls .__init__ # type: ignore[misc]
103+ init_method : Callable [..., None ] = self .__cls .__init__ # type: ignore[misc]
105104 # Ignore the case when __init__ is from object since there is no docstring
106105 # and its __doc__ cannot be assigned.
107106 if not isinstance (init_method , WrapperDescriptorType ):
108107 old_init_doc = init_method .__doc__
109- init_method .__doc__ = self ._cls .__doc__
108+ init_method .__doc__ = self .__cls .__doc__
110109 func = init_method
111110 init_doc_changed = True
112111
113112 if func is None :
114- func = self . _create_dummy_func_with_doc (self ._cls .__doc__ )
113+ func = _create_dummy_func_with_doc (self .__cls .__doc__ )
115114
116- docstring_inheritor = self ._docstring_inheritor (func )
115+ docstring_inheritor = self .__docstring_inheritor (func )
117116
118117 for parent_cls in self .__mro_classes :
119118 # As opposed to the attribute inheritance, and following the way a class is
@@ -123,15 +122,13 @@ def _inherit_class_docstring(
123122
124123 docstring_inheritor .render ()
125124
126- self ._cls .__doc__ = func .__doc__
125+ self .__cls .__doc__ = func .__doc__
127126
128127 if self ._init_in_class and init_doc_changed :
129128 init_method .__doc__ = old_init_doc
130129
131- def _inherit_attrs_docstrings (
132- self ,
133- ) -> None :
134- """Create the inherited docstrings for the class attributes."""
130+ def __inherit_methods_docstrings (self ) -> None :
131+ """Create the inherited docstrings for the class methods."""
135132 mro_classes = self .__mro_classes
136133 object_init_doc = self .__object_init_doc
137134 init_method_name = "__init__"
@@ -163,19 +160,19 @@ def _inherit_attrs_docstrings(
163160
164161 docstring_inheritor .render ()
165162
166- @staticmethod
167- def _create_dummy_func_with_doc (docstring : str | None ) -> Callable [..., Any ]:
168- """Create a dummy function with a given docstring.
169163
170- Args :
171- docstring: The docstring to be assigned .
164+ def _create_dummy_func_with_doc ( docstring : str | None ) -> Callable [..., Any ] :
165+ """Create a dummy function with a given docstring.
172166
173- Returns:
174- The function with the given docstring.
175- """
167+ Args:
168+ docstring: The docstring to be assigned.
169+
170+ Returns:
171+ The function with the given docstring.
172+ """
176173
177- def func () -> None : # pragma: no cover
178- pass
174+ def func () -> None : # pragma: no cover
175+ pass
179176
180- func .__doc__ = docstring
181- return func
177+ func .__doc__ = docstring
178+ return func
0 commit comments