4040
4141sphinx_version = list (map (float , re .findall (r'\d+' , sphinx .__version__ )[:3 ]))
4242
43- from sphinx .util import force_decode
43+ try :
44+ from sphinx .util import force_decode
45+ except ImportError :
46+ # force_decode has been removed with sphinx 4.0
47+ def force_decode (string : str , encoding : str ) -> str :
48+ return string
4449
4550
4651try :
@@ -89,6 +94,15 @@ def bool_option(*args):
8994 return "True"
9095
9196
97+ def _get_arg (param , pos , default , * args , ** kwargs ):
98+ if param in kwargs :
99+ return kwargs [param ]
100+ elif len (args ) > pos :
101+ return args [pos ]
102+ else :
103+ return default
104+
105+
92106class AutosummaryDocumenter (object ):
93107 """Abstract class for for extending Documenter methods
94108
@@ -369,13 +383,14 @@ def format_args(self):
369383 return None
370384 return process_signature (callmeth )
371385
372- def get_doc (self , encoding = None , ignore = 1 ):
386+ def get_doc (self , * args , ** kwargs ):
373387 """Reimplemented to include data from the call method"""
374388 content = self .env .config .autodata_content
375389 if content not in ('both' , 'call' ) or not self .get_attr (
376390 self .get_attr (self .object , '__call__' , None ), '__doc__' ):
377391 return super (CallableDataDocumenter , self ).get_doc (
378- encoding = encoding , ignore = ignore )
392+ * args , ** kwargs
393+ )
379394
380395 # for classes, what the "docstring" is can be controlled via a
381396 # config value; the default is both docstrings
@@ -413,13 +428,14 @@ def format_args(self):
413428 return None
414429 return process_signature (callmeth )
415430
416- def get_doc (self , encoding = None , ignore = 1 ):
431+ def get_doc (self , * args , ** kwargs ):
417432 """Reimplemented to include data from the call method"""
418433 content = self .env .config .autodata_content
419434 if content not in ('both' , 'call' ) or not self .get_attr (
420435 self .get_attr (self .object , '__call__' , None ), '__doc__' ):
421436 return super (CallableAttributeDocumenter , self ).get_doc (
422- encoding = encoding , ignore = ignore )
437+ * args , ** kwargs
438+ )
423439
424440 # for classes, what the "docstring" is can be controlled via a
425441 # config value; the default is both docstrings
@@ -435,10 +451,17 @@ def get_doc(self, encoding=None, ignore=1):
435451 docstrings .append (calldocstring + '\n ' )
436452
437453 doc = []
438- for docstring in docstrings :
439- if not isinstance (docstring , str ):
440- docstring = force_decode (docstring , encoding )
441- doc .append (prepare_docstring (docstring , ignore ))
454+ if sphinx_version < [4 , 0 ]:
455+ encoding = _get_arg ("encoding" , 0 , None , * args , ** kwargs )
456+ ignore = _get_arg ("ignore" , 1 , 1 , * args , ** kwargs )
457+ for docstring in docstrings :
458+ if not isinstance (docstring , str ):
459+ docstring = force_decode (docstring , encoding )
460+ doc .append (prepare_docstring (docstring , ignore ))
461+ else :
462+ ignore = _get_arg ("ignore" , 0 , 1 , * args , ** kwargs )
463+ for docstring in docstrings :
464+ doc .append (prepare_docstring (docstring , ignore ))
442465
443466 return doc
444467
0 commit comments