1919from sphinx .ext .autodoc ._member_finder import _filter_members , _get_members_to_document
2020from sphinx .ext .autodoc ._renderer import _add_content , _directive_header_lines
2121from sphinx .ext .autodoc ._sentinels import ALL
22- from sphinx .ext .autodoc .importer import _load_object_by_name , _resolve_name
22+ from sphinx .ext .autodoc .importer import _load_object_by_name
2323from sphinx .ext .autodoc .mock import ismock
2424from sphinx .locale import _ , __
2525from sphinx .pycode import ModuleAnalyzer
@@ -82,9 +82,6 @@ class Documenter:
8282 #: true if the generated content may contain titles
8383 titles_allowed : ClassVar = True
8484
85- __uninitialized_global_variable__ : ClassVar [bool ] = False
86- """If True, support uninitialized (type annotation only) global variables"""
87-
8885 option_spec : ClassVar [OptionSpec ] = {
8986 'no-index' : bool_option ,
9087 'no-index-entry' : bool_option ,
@@ -106,15 +103,7 @@ def __init__(
106103 self .options : _AutoDocumenterOptions = directive .genopt
107104 self .name = name
108105 self .indent : Final = indent
109- # the module and object path within the module, and the fully
110- # qualified name (all set after resolve_name succeeds)
111- self .modname : str = ''
112106 self .module : ModuleType | None = None
113- self .objpath : list [str ] = []
114- self .fullname = ''
115- # the object to document (set after import_object succeeds)
116- self .object : Any = None
117- self .object_name = ''
118107 # the parent/owner of the object to document
119108 self .parent : Any = None
120109 # the module analyzer to get at attribute docs, or None
@@ -132,11 +121,6 @@ def __init__(
132121 self .options .special_members += ['__new__' , '__init__' ]
133122 self .options = self .options .merge_member_options ()
134123
135- @property
136- def documenters (self ) -> dict [str , type [Documenter ]]:
137- """Returns registered Documenter classes"""
138- return self .env ._registry .documenters
139-
140124 def add_line (self , line : str , source : str , * lineno : int , indent : str ) -> None :
141125 """Append one line of generated reST to the output."""
142126 if line .strip (): # not a blank line
@@ -145,6 +129,10 @@ def add_line(self, line: str, source: str, *lineno: int, indent: str) -> None:
145129 self .directive .result .append ('' , source , * lineno )
146130
147131 def _load_object_by_name (self ) -> Literal [True ] | None :
132+ """Import the object given by *self.name*.
133+
134+ Returns True if parsing and resolving was successful, otherwise None.
135+ """
148136 if self ._load_object_has_been_called :
149137 return True
150138
@@ -165,107 +153,11 @@ def _load_object_by_name(self) -> Literal[True] | None:
165153 props , module , parent = ret
166154
167155 self .props = props
168- self .modname = props .module_name
169- self .objpath = list (props .parts )
170- self .fullname = props .full_name
171156 self .module = module
172157 self .parent = parent
173- self .object_name = props .object_name
174- self .object = props ._obj
175158 self ._load_object_has_been_called = True
176159 return True
177160
178- def resolve_name (
179- self , modname : str | None , parents : Any , path : str , base : str
180- ) -> tuple [str | None , list [str ]]:
181- """Resolve the module and name of the object to document given by the
182- arguments and the current module/class.
183-
184- Must return a pair of the module name and a chain of attributes; for
185- example, it would return ``('zipfile', ['ZipFile', 'open'])`` for the
186- ``zipfile.ZipFile.open`` method.
187- """
188- ret = _resolve_name (
189- objtype = self .objtype ,
190- module_name = modname ,
191- path = path ,
192- base = base ,
193- parents = parents ,
194- current_document = self ._current_document ,
195- ref_context_py_module = self .env .ref_context .get ('py:module' ),
196- ref_context_py_class = self .env .ref_context .get ('py:class' , '' ),
197- )
198- if ret is not None :
199- module_name , parts = ret
200- return module_name , list (parts )
201-
202- msg = 'must be implemented in subclasses'
203- raise NotImplementedError (msg )
204-
205- def parse_name (self ) -> bool :
206- """Determine what module to import and what attribute to document.
207-
208- Returns True and sets *self.modname*, *self.objpath*, *self.fullname*,
209- *self.args* and *self.retann* if parsing and resolving was successful.
210- """
211- return self ._load_object_by_name () is not None
212-
213- def import_object (self , raiseerror : bool = False ) -> bool :
214- """Import the object given by *self.modname* and *self.objpath* and set
215- it as *self.object*.
216-
217- Returns True if successful, False if an error occurred.
218- """
219- return self ._load_object_by_name () is not None
220-
221- def get_real_modname (self ) -> str :
222- """Get the real module name of an object to document.
223-
224- It can differ from the name of the module through which the object was
225- imported.
226- """
227- return self .props ._obj___module__ or self .props .module_name
228-
229- def check_module (self ) -> bool :
230- """Check if *self.object* is really defined in the module given by
231- *self.modname*.
232- """
233- if self .options .imported_members :
234- return True
235-
236- subject = inspect .unpartial (self .props ._obj )
237- modname = self .get_attr (subject , '__module__' , None )
238- return not modname or modname == self .props .module_name
239-
240- def format_args (self , ** kwargs : Any ) -> str :
241- """Format the argument signature of *self.object*.
242-
243- Should return None if the object does not have a signature.
244- """
245- return ''
246-
247- def format_name (self ) -> str :
248- """Format the name of *self.object*.
249-
250- This normally should be something that can be parsed by the generated
251- directive, but doesn't need to be (Sphinx will display it unparsed
252- then).
253- """
254- # normally the name doesn't contain the module (except for module
255- # directives of course)
256- return self .props .dotted_parts or self .props .module_name
257-
258- def _call_format_args (self , ** kwargs : Any ) -> str :
259- if kwargs :
260- try :
261- return self .format_args (** kwargs )
262- except TypeError :
263- # avoid chaining exceptions, by putting nothing here
264- pass
265-
266- # retry without arguments for old documenters
267- return self .format_args ()
268-
269161 def add_directive_header (self , * , indent : str ) -> None :
270162 """Add the directive header and options to the generated content."""
271163 domain_name = getattr (self , 'domain' , 'py' )
@@ -298,7 +190,7 @@ def get_sourcename(self) -> str:
298190 obj_module = inspect .safe_getattr (self .props ._obj , '__module__' , None )
299191 obj_qualname = inspect .safe_getattr (self .props ._obj , '__qualname__' , None )
300192 if obj_module and obj_qualname :
301- # Get the correct location of docstring from self.object
193+ # Get the correct location of docstring from props._obj
302194 # to support inherited methods
303195 fullname = f'{ self .props ._obj .__module__ } .{ self .props ._obj .__qualname__ } '
304196 else :
@@ -801,22 +693,6 @@ class ClassDocumenter(Documenter):
801693 'noindex' : bool_option ,
802694 }
803695
804- def get_canonical_fullname (self ) -> str | None :
805- __modname__ = safe_getattr (
806- self .props ._obj , '__module__' , self .props .module_name
807- )
808- __qualname__ = safe_getattr (self .props ._obj , '__qualname__' , None )
809- if __qualname__ is None :
810- __qualname__ = safe_getattr (self .props ._obj , '__name__' , None )
811- if __qualname__ and '<locals>' in __qualname__ :
812- # No valid qualname found if the object is defined as locals
813- __qualname__ = None
814-
815- if __modname__ and __qualname__ :
816- return f'{ __modname__ } .{ __qualname__ } '
817- else :
818- return None
819-
820696
821697class ExceptionDocumenter (ClassDocumenter ):
822698 """Specialized ClassDocumenter subclass for exceptions."""
@@ -831,8 +707,6 @@ class DataDocumenter(Documenter):
831707
832708 props : _AssignStatementProperties
833709
834- __uninitialized_global_variable__ = True
835-
836710 objtype = 'data'
837711 option_spec : ClassVar [OptionSpec ] = dict (Documenter .option_spec )
838712 option_spec ['annotation' ] = annotation_option
@@ -858,12 +732,6 @@ class AttributeDocumenter(Documenter):
858732 option_spec ['annotation' ] = annotation_option
859733 option_spec ['no-value' ] = bool_option
860734
861- @staticmethod
862- def is_function_or_method (obj : Any ) -> bool :
863- return (
864- inspect .isfunction (obj ) or inspect .isbuiltin (obj ) or inspect .ismethod (obj )
865- )
866-
867735
868736class PropertyDocumenter (Documenter ):
869737 """Specialized Documenter subclass for properties."""
@@ -887,18 +755,6 @@ class TypeAliasDocumenter(Documenter):
887755 }
888756
889757
890- class DocstringSignatureMixin :
891- """Retained for compatibility."""
892-
893-
894- class ModuleLevelDocumenter (Documenter ):
895- """Retained for compatibility."""
896-
897-
898- class ClassLevelDocumenter (Documenter ):
899- """Retained for compatibility."""
900-
901-
902758def autodoc_attrgetter (
903759 obj : Any , name : str , * defargs : Any , registry : SphinxComponentRegistry
904760) -> Any :
@@ -924,7 +780,7 @@ def _document_members(
924780 for documenter , is_attr in member_documenters :
925781 assert documenter .props .module_name
926782 # We can directly call ._generate() since the documenters
927- # already called parse_name() and import_object() before.
783+ # already called ``_load_object_by_name()`` before.
928784 #
929785 # Note that those two methods above do not emit events, so
930786 # whatever objects we deduced should not have changed.
0 commit comments