,>SEdZddlmZddlmZddlZddlmZmZmZddl m Z ddl m Z ddl mZdd lmZmZmZmZmZmZdd lmZd Z dddZGddeZdS)z5Special methods checker and helper function's module.) annotations)CallableN)basesnodesutil)InferenceContext)InferenceResult) BaseChecker) PYMETHODSSPECIAL_METHODS_PARAMSdecorated_withis_function_body_ellipsisonly_required_for_messages safe_infer)PyLinter__next__nodenodes.FunctionDefcallercontextInferenceContext | NonereturnInferenceResult | Nonec |||}t|}n"#tj$rYdSt$rYdSwxYw t|dS#tj$rYdSt$r|cYSwxYw)zSafely infer the return value of a function. Returns None if inference failed or if there is some ambiguity (more than one node has been inferred). Otherwise, returns inferred value. )rN)infer_call_resultnextastroidInferenceError StopIteration)rrrinferitvalues /builddir/build/BUILD/cloudlinux-venv-1.0.10/venv/lib/python3.11/site-packages/pylint/checkers/classes/special_methods_checker.py_safe_infer_call_resultr#s(((AAW   !tt tt W t  !tt  s,&)A AA AA=/ A=<A=ceZdZdZdZdddedddd gifd d d dd gifdddddddddddd ZdGfd Zed ddd d!d"d#d$d%d&d'd(d) dHd,Z e Z dHd-Z e dId2Z e dJd3Ze dJd4Ze dJd5Ze dJd6Ze dJd7Ze dJd8Ze dJd9ZdKd;ZdKd<ZdKd=ZdKd>ZdKd?ZdKd@ZdKdAZdKdBZdKdCZdKdDZdKdEZdKdFZ xZ!S)LSpecialMethodsCheckerzOChecker which verifies that special methods are implemented correctly. classesz__iter__ returns non-iteratornon-iterator-returnedzVUsed when an __iter__ method returns something which is not an iterable (i.e. has no `z ` method) old_names)W0234zold-non-iterator-returned-1)E0234zold-non-iterator-returned-2z6The special method %r expects %s param(s), %d %s given#unexpected-special-method-signaturezEmitted when a special method was defined with an invalid number of parameters. If it has too few or too many, it might not work at all.)E0235zbad-context-manager)z,__len__ does not return non-negative integerinvalid-length-returnedzPUsed when a __len__ method returns something which is not a non-negative integer)z__bool__ does not return boolinvalid-bool-returnedzAUsed when a __bool__ method returns something which is not a bool)z__index__ does not return intinvalid-index-returnedzGUsed when an __index__ method returns something which is not an integer)z__repr__ does not return strinvalid-repr-returnedzCUsed when a __repr__ method returns something which is not a string)z__str__ does not return strinvalid-str-returnedzBUsed when a __str__ method returns something which is not a string)z__bytes__ does not return bytesinvalid-bytes-returnedzAUsed when a __bytes__ method returns something which is not bytes)z__hash__ does not return intinvalid-hash-returnedzEUsed when a __hash__ method returns something which is not an integer)z4__length_hint__ does not return non-negative integerinvalid-length-hint-returnedzXUsed when a __length_hint__ method returns something which is not a non-negative integer)z__format__ does not return strinvalid-format-returnedzEUsed when a __format__ method returns something which is not a string)z&__getnewargs__ does not return a tupleinvalid-getnewargs-returnedzHUsed when a __getnewargs__ method returns something which is not a tuple)zB__getnewargs_ex__ does not return a tuple containing (tuple, dict)invalid-getnewargs-ex-returnedzbUsed when a __getnewargs_ex__ method returns something which is not of the form tuple(tuple, dict)) E0301E0302E0303E0304E0305E0306E0307E0308E0309E0310E0311E0312E0313linterrrNonec t||j|j|j|j|j|j|j|j |j |j |j |j d |_dS)N) __iter____len____bool__ __index____repr____str__ __bytes____hash____length_hint__ __format____getnewargs____getnewargs_ex__)super__init__ _check_iter _check_len _check_bool _check_index _check_repr _check_str _check_bytes _check_hash_check_length_hint _check_format_check_getnewargs_check_getnewargs_ex _protocol_map)selfrE __class__s r"rUzSpecialMethodsChecker.__init__s{    ((*(*(#6,"4!%!:  r-r.r/r0r1r2r3r4r5r6r7rrc|sdSt||}|r9|j|jvr+t |s|j|j|||jt vr||dSdSN) is_methodr#namerbrr "_check_unexpected_method_signaturercrinferreds r"visit_functiondefz'SpecialMethodsChecker.visit_functiondefs ~~  F*466  : T///-d330 *D ty )$ 9 9 9 9 ! !  3 3D 9 9 9 9 9 " !rec|t|j}|dS|jjs|jjsdSt |dgr |jj}n|jjdd}t |t |jjz }t |jj}||z}d}t|tr||v}d|dd|d}n3||z }|dkrd}n%|dkrd}n|dkr||z dkp |jj }|r-|dkrdnd } | d |j||| f| dSdS) Nzbuiltins.staticmethodFzbetween rz or Twaswerer+)argsr) r rirrvarargr lendefaults isinstancetuple add_message) rcrexpected_paramsall_args mandatoryoptionalcurrent_paramsemitrestverbs r"rjz8SpecialMethodsChecker._check_unexpected_method_signatures0;  " Fy~ di&6  F $!8 9 : : *y~HHy~abb)HMMC (:$;$;; ty)**"X- ou - - HO3DV);UUQRASUUOO #Y.Dqyy%_2Fdi6FG  *a//55VD   5i.$G        rer type_strboolct|tjo%|j|kot|tj Srg)rvrInstancerirConst)rrs r"_is_wrapped_typez&SpecialMethodsChecker._is_wrapped_types> tU^ , , 2 U" 2tU[111 rect|drdSt|tjot|jt S)NintT)r%rrvrrr!rrs r"_is_intzSpecialMethodsChecker._is_intB 1 1$ > > 4$ ,,LDJ1L1LLrect|drdSt|tjot|jt S)NrT)r%rrvrrr!rrs r"_is_strzSpecialMethodsChecker._is_strrrect|drdSt|tjot|jt S)NrT)r%rrvrrr!rrs r"_is_boolzSpecialMethodsChecker._is_bool B 1 1$ ? ? 4$ ,,MDJ1M1MMrect|drdSt|tjot|jt S)NbytesT)r%rrvrrr!rrs r" _is_byteszSpecialMethodsChecker._is_bytesB 1 1$ @ @ 4$ ,,NDJ1N1NNrect|drdSt|tjot|jt S)NrwT)r%rrvrrr!rwrs r" _is_tuplezSpecialMethodsChecker._is_tuplerrect|drdSt|tjot|jt S)NdictT)r%rrvrrr!rrs r"_is_dictzSpecialMethodsChecker._is_dict"rrect|tjrdSt|tjrdSt|tjr2 |tdS#tj $rYnwxYwt|tj rb| }|rLt|tj r2 |tdS#tj $rYnwxYwdS)NTF) rvr GeneratorrComprehensionScoper local_attr NEXT_METHODr NotFoundErrorClassDef metaclass)rrs r" _is_iteratorz"SpecialMethodsChecker._is_iterator)s  dEO , , 4 dE4 5 5 4 dEN + +   ,,,t(     en - - ((I Z 5>BB ((5554,Dus$A00BBC,,C>=C>rlcb||s|d|dSdS)Nr'r)rrxrks r"rVz!SpecialMethodsChecker._check_iterBsE  ** A   44  @ @ @ @ @ A Arec||s|d|dSt|tjr$|jdkr|d|dSdSdS)Nr-rrrrxrvrrr!rks r"rWz SpecialMethodsChecker._check_lenFs||H%% C   6T  B B B B B %+ . . C8>A3E3E   6T  B B B B B C C3E3Erecb||s|d|dSdS)Nr.r)rrxrks r"rXz!SpecialMethodsChecker._check_boolLsC}}X&& A   44  @ @ @ @ @ A Arecb||s|d|dSdS)Nr/rrrxrks r"rYz"SpecialMethodsChecker._check_indexPsC||H%% B   5D  A A A A A B Brecb||s|d|dSdS)Nr0rrrxrks r"rZz!SpecialMethodsChecker._check_reprTC||H%% A   44  @ @ @ @ @ A Arecb||s|d|dSdS)Nr1rrrks r"r[z SpecialMethodsChecker._check_strXsC||H%% @   3$  ? ? ? ? ? @ @recb||s|d|dSdS)Nr2r)rrxrks r"r\z"SpecialMethodsChecker._check_bytes\sC~~h'' B   5D  A A A A A B Brecb||s|d|dSdS)Nr3rrrks r"r]z!SpecialMethodsChecker._check_hash`rrec||s|d|dSt|tjr$|jdkr|d|dSdSdS)Nr4rrrrks r"r^z(SpecialMethodsChecker._check_length_hintds||H%% H   ;$  G G G G G %+ . . H8>A3E3E   ;$  G G G G G H H3E3Erecb||s|d|dSdS)Nr5rrrks r"r_z#SpecialMethodsChecker._check_formatlsC||H%% C   6T  B B B B B C Crecb||s|d|dSdS)Nr6r)rrxrks r"r`z'SpecialMethodsChecker._check_getnewargspsE~~h'' G   :  F F F F F G Grec||s|d|dSt|tjsdSd}t |jdkrd}n|jd|jf|jd|jffD]Y\}}t|tjrt|}|r)t|tj s||sd}nZ|r|d|dSdS)Nr7rFTrro) rrxrvrTuplerteltsrCallrrUninferableBase)rcrrl found_errorargchecks r"raz*SpecialMethodsChecker._check_getnewargs_exvs7~~h''    =D  I I I F(EK00  F x}   " "KKq!4>2q!4=1   Uc5:..*$S//Cz#t/CDD 5::&*   J   =D  I I I I I J Jre)rErrrF)rrrrF)rr rrrr)rr rr)rrrlr rrF)"__name__ __module__ __qualname____doc__rirmsgsrUrrmvisit_asyncfunctiondefrj staticmethodrrrrrrrrrVrWrXrYrZr[r\r]r^r_r`ra __classcell__)rds@r"r%r%8s D , # =&1 = = =<<    E 1 2;< =             WQ Q Df      & -!  &!%(:::: /0000d   \ MMM\M MMM\M NNN\N OOO\O OOO\O NNN\N \0AAAACCCC AAAABBBBAAAA@@@@BBBBAAAAHHHHCCCCGGGG JJJJJJJJrer%rg)rrrrrrrr)r __future__rcollections.abcrrrrrastroid.contextrastroid.typingr pylint.checkersr pylint.checkers.utilsr r r rrrpylint.lint.pylinterrrr#r%rer"rs] <;""""""$$$$$$&&&&&&&&&&,,,,,,******''''''*))))) (,4[J[J[J[J[JK[J[J[J[J[Jre