o Wa@sdZddlZddlZddlZddlmZmZmZmZddl m Z ddl m Z ddl mZddl mZddlmZeeZGd d d Zd ed ejfd dZdeedejd eefddZde d eded dfddZde d eeeffddZdS)aF sphinx.ext.autodoc.preserve_defaults ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Preserve the default argument values of function signatures in source code and keep them not evaluated for readability. :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. N)AnyDictListOptional)Sphinx)__)parse)unparse)loggingc@s,eZdZdeddfddZdefddZdS) DefaultValuenamereturnNcCs ||_dSNr )selfr rF/usr/lib/python3/dist-packages/sphinx/ext/autodoc/preserve_defaults.py__init__s zDefaultValue.__init__cCs|jSrr)rrrr__repr__szDefaultValue.__repr__)__name__ __module__ __qualname__strrrrrrrr sr objr c Cs`z#t|}|drtd|}|jdjdWSt|}|jdWSttfy/YdSw)zGet FunctionDef object from living object. This tries to parse original code for living object and returns AST node for given *obj*.  z\tz if True: rN)inspect getsource startswith ast_parsebodyOSError TypeError)rsourcemodulerrrget_function_def"s    r%linespositionc Cs\z!tjdkr WdS|j|jkr||jd}||j|jWSWdSttfy-YdSw)N))sys version_infolineno end_lineno col_offsetend_col_offsetAttributeError IndexError)r&r'linerrrget_default_value5s  r4app bound_methodc Cs|jjsdSzt|}|ddr|ddWn ttfy)g}Ynwzt |}|j j s7|j j rt |}t|j j }t|j j }t|j}t|D]L\} } | j| jur| j| j| jfvr|d} t|| } | durxt| } | jt| d|| <qS|d} t|| } | durt| } | jt| d|| <qS|j|d}||_WdSWdSttfyYdSty} zt t!d|| WYd} ~ dSd} ~ ww)z2Update defvalue info of *obj* using type_comments.Nrr)default) parametersz3Failed to parse a default argument value for %r: %s)"configautodoc_preserve_defaultsrr splitlinesrinsertr!r"r%argsdefaults kw_defaults signaturelistr9values enumerater8emptykindPOSITIONAL_ONLYPOSITIONAL_OR_KEYWORDpopr4 ast_unparsereplacer __signature__r1NotImplementedErrorloggerwarningr)r5rr6r&functionsigr?r@r9iparamr8valueexcrrrupdate_defvalueCsP            rVcCs$|ddd|dtdddS)Nr;FTz autodoc-before-process-signaturez1.0)versionparallel_read_safe)add_config_valueconnectrV)r5rrrsetupms  r[) __doc__astrr+typingrrrrsphinx.applicationr sphinx.localersphinx.pycode.astrrr rJ sphinx.utilr getLoggerrrNr FunctionDefr%rASTr4boolrVr[rrrrs         *