L i)PdZddlmZmZmZddlmZmZddlZgdZ edede fZ Gd d eZ dd e d ee e fdzd e fdZde d e fdZde de d e fdZde de d e fdZdee d efdZdd ee e fded e fdZd ee e fd ee e ffdZd e d e fdZde de de d e fdZy) zkUtilities to allow inserting docstring fragments for common parameters into function and method docstrings.)CallableIterableMapping)ProtocolTypeVarN) docformatinherit_docstring_fromindentcount_linesfilldoc unindent_dictunindent_stringextend_notes_in_docstringreplace_notes_in_docstring doc_replace_F.)boundc eZdZdZdedefdZy) DecoratorzA decorator of a function.funcreturncyN)selfrs W/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/_lib/doccer.py__call__zDecorator.__call__sN)__name__ __module__ __qualname____doc__rrrrrrrs$.R.r.rr docstringdocdictrcF|s|S|i}|s|S|jj}t|dkrd}nt|dd}d|z}i}|j D]:\}}|jj}d|zj |||<<||zS)abFill a function docstring from variables in dictionary. Adapt the indent of the inserted docs Parameters ---------- docstring : str A docstring from a function, possibly with dict formatting strings. docdict : dict[str, str], optional A dictionary with keys that match the dict formatting strings and values that are docstring fragments to be inserted. The indentation of the inserted docstrings is set to match the minimum indentation of the ``docstring`` by adding this indentation to all lines of the inserted string, except the first. Returns ------- docstring : str string with requested ``docdict`` strings inserted. Examples -------- >>> docformat(' Test string with %(value)s', {'value':'inserted value'}) ' Test string with inserted value' >>> docstring = 'First line\n Second line\n %(value)s' >>> inserted_string = "indented\nstring" >>> docdict = {'value': inserted_string} >>> docformat(docstring, docdict) 'First line\n Second line\n indented\n string' Nr  ) expandtabs splitlineslenr itemsjoin)r"r#linesicountindentindentednamedstrs rrrs@    " - - /E 5zA~"59- 6\FHmmo5 d!,,.---e45 x rclsc,dtdtffd }|S)aThis decorator modifies the decorated function's docstring by replacing occurrences of '%(super)s' with the docstring of the method of the same name from the class `cls`. If the decorated method has no docstring, it is simply given the docstring of `cls`s method. Parameters ---------- cls : type or object A class with a method with the same name as the decorated method. The docstring of the method in this class replaces '%(super)s' in the docstring of the decorated method. Returns ------- decfunc : function The decorator function that modifies the __doc__ attribute of its argument. Examples -------- In the following, the docstring for Bar.func created using the docstring of `Foo.func`. >>> class Foo: ... def func(self): ... '''Do something useful.''' ... return ... >>> class Bar(Foo): ... @inherit_docstring_from(Foo) ... def func(self): ... '''%(super)s ... Do it fast. ... ''' ... return ... >>> b = Bar() >>> b.func.__doc__ 'Do something useful. Do it fast. ' rrct|jj}|j}| ||_|S|t|z}||_|S)N)super)getattrrr!dict)r cls_docstringfunc_docstring new_docstringr4s r_docz$inherit_docstring_from.._doc~sST]]3;;   !(DL +T -FFM(DL rr)r4r=s` rr r RsX2" Krnotesc0dtdtffd }|S)aThis decorator replaces the decorated function's docstring with the docstring from corresponding method in `cls`. It extends the 'Notes' section of that docstring to include the given `notes`. Parameters ---------- cls : type or object A class with a method with the same name as the decorated method. The docstring of the method in this class replaces the docstring of the decorated method. notes : str Additional notes to append to the 'Notes' section of the docstring. Returns ------- decfunc : function The decorator function that modifies the __doc__ attribute of its argument. rrct|jj}||S|jd}|dk(r!|jd}|dk(r t |}|d|z||dz|_|S)N References  Examples r8rr!findr+)rr: end_of_notesr4r?s rr=z'extend_notes_in_docstring.._docsT]]3;;   K$))*@A 2 (--.BCLr!"=1 -< (5 0=3O O  rr>r4r?r=s`` rrrs,2" Krc0dtdtffd }|S)aThis decorator replaces the decorated function's docstring with the docstring from corresponding method in `cls`. It replaces the 'Notes' section of that docstring with the given `notes`. Parameters ---------- cls : type or object A class with a method with the same name as the decorated method. The docstring of the method in this class replaces the docstring of the decorated method. notes : str The notes to replace the existing 'Notes' section with. Returns ------- decfunc : function The decorator function that modifies the __doc__ attribute of its argument. rrc"t|jj}d}||S|j|}|jd}|dk(r!|jd}|dk(r t |}|d|t |zz||dz|_|S)Nz Notes ----- rBrCrDrE)rr: notes_headerstart_of_notesrGr4r?s rr=z(replace_notes_in_docstring.._docsT]]3;; 7   K&++L9$))*@A 2 (--.BCLr!"=1 >NS->> ? LM* +  rr>rHs`` rrrs,2"( Krr.ctj}|D]6}|j}|st|t |t |z }8|tjk(ry|S)aMinimum indent for all lines in line list Parameters ---------- lines : Iterable[str] The lines to find the minimum indent of. Returns ------- indent : int The minimum indent. Examples -------- >>> lines = [' one', ' two', ' three'] >>> indentcount_lines(lines) 1 >>> lines = [] >>> indentcount_lines(lines) 0 >>> lines = [' one'] >>> indentcount_lines(lines) 1 >>> indentcount_lines([' ']) 0 r)sysmaxsizelstripminr+)r.indentnolinestrippeds rr r s[8{{H@;;= 8SYX%>?H@3;; Orunindent_paramscF|r tdtdtffd }|S)aReturn docstring decorator using docdict variable dictionary. Parameters ---------- docdict : dict[str, str] A dictionary containing name, docstring fragment pairs. unindent_params : bool, optional If True, strip common indentation from all parameters in docdict. Default is False. Returns ------- decfunc : function The decorator function that applies dictionary to its argument's __doc__ attribute. rrcJ|jxsd}t||_|S)N)r!r)rdocr#s rdecoratezfilldoc..decorates$ll b g.  r)r r)r#rUrZs` rr r s,"(rb OrcVi}|jD]\}}t|||<|S)aUnindent all strings in a docdict. Parameters ---------- docdict : dict[str, str] A dictionary with string values to unindent. Returns ------- docdict : dict[str, str] The `docdict` dictionary but each of its string values are unindented. )r,r )r#can_dictr2r3s rr r $s5 "Hmmo/ d(./ Orc|jj}t|}|dk(r|Sdj|Dcgc]}||d c}Scc}w)aqSet docstring to minimum indent for all lines, including first. Parameters ---------- docstring : str The input docstring to unindent. Returns ------- docstring : str The unindented docstring. Examples -------- >>> unindent_string(' two') 'two' >>> unindent_string(' two\n three') 'two\n three' rr(N)r)r*r r-)r"r.r/rSs rr r 7sU(  " - - /E u %F { 996d67m6 776s Aobjoldvalnewvalcl|jxsdj||dtdtffd }|S)azDecorator to take the docstring from obj, with oldval replaced by newval Equivalent to ``func.__doc__ = obj.__doc__.replace(oldval, newval)`` Parameters ---------- obj : object A class or object whose docstring will be used as the basis for the replacement operation. oldval : str The string to search for in the docstring. newval : str The string to replace `oldval` with in the docstring. Returns ------- decfunc : function A decorator function that replaces occurrences of `oldval` with `newval` in the docstring of the decorated function. rXrrc|_|Sr)r!)rrYs rinnerzdoc_replace..innerjs  r)r!replacer)r^r_r`rcrYs @rrrRs:, ;; " % %ff 5CB2 Lrr)T)r!collections.abcrrrtypingrrrN__all__objectrrstrrr rrintr boolr r9r r rrrrrlsH387$   T#v+./// 2 2 wsCx'84'?2 32 j6696r&6&#&)&R*F*3*9*Z#Xc]#s#LWS#X&:738,c3h&8s8s86VS#)r