,>SE d Z ddlmZ ddlmZ ddlZddlmZmZmZ ddl m Z ddlmZ ddl mZ dd lmZmZmZmZmZmZ dd lmZ dZ dddZ G d de ZdS )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"# t j $ r Y dS t $ r Y dS w xY w t | dS # t j $ r Y dS t $ r |cY S w xY w)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. )r N)infer_call_resultnextastroidInferenceError StopIteration)r r r inferitvalues /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 ttW t! tt s, &) A AAA A=/A=<A=c e Zd ZdZdZddde dddd gifd dddd gifdddddddddddd ZdG fdZ edddd d!d"d#d$d%d&d'd(d) dHd, Z e Z dHd-ZedId2 Z edJd3 ZedJd4 ZedJd5 ZedJd6 ZedJd7 ZedJd8 ZedJd9 ZdKd;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)) E0301E0302E0303E0304E0305E0306E0307E0308E0309E0310E0311E0312E0313linterr r Nonec t | | j | j | j | j | j | j | j | j | j | j | j | j d| _ d S )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" rU zSpecialMethodsChecker.__init__ s{ ((*(*(#6,"4!%!: r- r. r/ r0 r1 r2 r3 r4 r5 r6 r7 r r c | sd S t || }|r9|j | j v r+t | s | j |j || |j t v r| | d S d S N) is_methodr# namerb r r "_check_unexpected_method_signaturerc r inferreds r" visit_functiondefz'SpecialMethodsChecker.visit_functiondef s ~~ F*466 : T///-d33 0 *Dty)$9999 !!33D99999 "!re c | t |j }|d S |j j s|j j sd S t |dg r |j j }n|j j dd }t | t |j j z }t |j j }||z }d}t |t r||v}d|d d|d }n3||z }|dk rd}n%|dk rd}n|dk r||z dk p|j j }|r-|dk rdnd } | d |j ||| f| d S d S )Nzbuiltins.staticmethod Fzbetween r z or Twaswerer+ )argsr ) r ri rr varargr lendefaults isinstancetupleadd_message) rc r expected_paramsall_args mandatoryoptionalcurrent_paramsemitrestverbs r" rj z8SpecialMethodsChecker._check_unexpected_method_signature s 0;"Fy~ di&6 F$!8 9:: *y~HHy~abb)HMMC (:$;$;; ty)**"X-ou-- H O3D V);UUQRASUUOO #Y.Dqyy%_2Fdi6FG *a//55VD5i.$G re r type_strboolc t | t j o%| j |k ot | t j S rg )rv r Instanceri r Const)r r s r" _is_wrapped_typez&SpecialMethodsChecker._is_wrapped_type