bgH,dZddlmZddlmZddlmZmZmZm Z m Z m Z ddl m Z mZddlmZmZmZmZmZddlmZddlmZmZd)dZd*dZ d+d,dZ d+d-dZ d+d.dZd+d.dZd+d.dZ d+d/d Z!d+d0d"Z"d1d#Z#d1d$Z$d1d%Z%d2d'Z&d+d.d(Z'dS)3zVarious helper utilities.) annotations) Generator)basesmanagernodesobjects raw_buildingutil) CallContextInferenceContext)AstroidTypeErrorAttributeInferenceErrorInferenceErrorMroError_NonDeducibleTypeHierarchy) scoped_nodes)InferenceResultSuccessfulInferenceResultcls_namestrbuiltins nodes.Modulereturnnodes.ClassDefc<tj|}||_|SN)r build_classparent)rrproxys `/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/astroid/helpers.py_build_proxy_classr!s  $X . .EEL Lfunction"nodes.Lambda | bases.UnboundMethodct|tjr#|jdkrd}n"d}nt|t jrd}nd}t||S)Nrbuiltin_function_or_methodr#method) isinstancerLambdarootnamer BoundMethodr!)r#rrs r _function_typer-sn(L/00 ==?? : - -3HH!HH He/ 0 0 h 1 11r"NnodercontextInferenceContext | None-Generator[InferenceResult | None, None, None]c#NKtj}|j}|p t}||D]`}t |t jrB|jr| |}|r|VA| ddV_t |t j tj frt||Vt |t jrt!d|Vt |t"jrt&t |t(jr|Vt |tjt"jt0jfr |jVBt7dt9|ddS)Nr/typermodulezWe don't handle z currently)rAstroidManagerbuiltins_moduler inferr(rClassDefnewstyle metaclassgetattrr)r UnboundMethodr-Moduler!rUnknownrr UninferableBaseProxySlicerSuper_proxiedAssertionErrorr4)r.r/astroid_managerrinferredr;s r _object_typerH-s,..O.H+)++GJJwJ//PP h 5 6 6 P  $..w.?? #OOO""6**1- - - - - <#68K"L M M P 844 4 4 4 4 ,"5 6 6 P$Xx88 8 8 8 8 %- 0 0 P $"6 7 7 PNNNN 5; W]"K L L P# # # # # !NDNN!N!N!NOO O'PPr"InferenceResult | Nonec tt||}n#t$rtjcYSwxYwt |dks|s tjSt |dS)aVObtain the type of the given node. This is used to implement the ``type`` builtin, which means that it's used for inferring type calls, as well as used in a couple of other places in the inference. The node will be inferred first, so this function can support all sorts of objects, as long as they support inference. r)setrHrr Uninferablelenlist)r.r/typess r object_typerQJsv Lw//00      5zzA~~U~ ;;q>s  99cLt|ttfs|f}n|}t|tjr tjSd|D}|D]L}t|tjrt d|D] }||krdS MdS)Nc^g|]*}t|tjs|n tj+S)r(rInstancer rM).0items r z,_object_type_is_subclass..ks@ tU^44J$:Jr"z&arg 2 must be a type or tuple of typesTF)r(tuplerOr r@rMr mro)obj_type class_or_seqr/ class_seqklass obj_subclasss r _object_type_is_subclassr`_s lUDM 2 2!!O  (D011 I eT1 2 2 M"#KLL L$LLNN  Lu$$ttt%  5r"ct||}t|tjr tjSt |||S)zCheck if a node 'isinstance' any node in class_or_seq. :param node: A given node :param class_or_seq: Union[nodes.NodeNG, Sequence[nodes.NodeNG]] :rtype: bool :raises AstroidTypeError: if the given ``classes_or_seq`` are not types r3)rQr(r r@rMr`)r.r\r/r[s r object_isinstancerb|sF4))H(D011  #HlG L L LLr"c~t|tjst|dt |||S)asCheck if a type is a subclass of any node in class_or_seq. :param node: A given node :param class_or_seq: Union[Nodes.NodeNG, Sequence[nodes.NodeNG]] :rtype: bool :raises AstroidTypeError: if the given ``classes_or_seq`` are not types :raises AstroidError: if the type of the given node cannot be inferred or its type's mro doesn't work z needs to be a ClassDef noder3)r(rr9 TypeErrorr`)r.r\r/s r object_issubclassresD dEN + +?4===>>> #D, H H HHr"nodes.NodeNG | bases.Proxyc ||}t|}n#ttf$rYdSwxYw t|dS#t$rYdSt$r|cYSwxYw)zReturn the inferred value for the given node. Return None if inference failed or if there is some ambiguity (more than one node has been inferred). r3N)r8nextr StopIteration)r.r/inferitvalues r safe_inferrls**W*--W  M *tt W t tt  s$%(==A A- A-,A-boolc |jS#t$rYnwxYw|jD]L}t||}t |t jr||ust||s d|_dSMd|_dS)z=Return whether all base classes of a class could be inferred.r3FT)_all_bases_knownAttributeErrorrrlr(rr9has_known_bases)r^r/baseresults r rqrqs %%        D'2226<#899 "67;;;&+E "55  "E 4s  cttt||fstt|j|jgsdS ||ddvS#t $r }t|d}~wwxYw)NF)allmaprqrr:rZr)type1type2es r _type_checkr{s s?UEN33 4 4)(( / 0 0u0 CRC((( 000(a/0s A(( A?2A::A?c$t||S)z)Check if *type1* is a subtype of *type2*.rxryr{r}s r is_subtypers U% 0 0 00r"c"t||S)z+Check if *type2* is a supertype of *type1*.r~r}s r is_supertypers ue $ $$r"nodes.Const | Nonect} |d|D]}t|tjs||_t g||_|||D]<}t|tj r t|j tr|ccS=n#t$rYnwxYwdS)zGet the value as an index for the given instance. If an instance provides an __index__ method, then it can be used in some scenarios where an integer is expected, for instance when multiplying or subscripting a list. __index__r3)argscalleeN)r igetattrr(rr, boundnoder callcontextinfer_call_resultrConstrkintr)r.r/rGrss r class_instance_as_indexrs  G   k7 CC " "Hh(9::  $G "-2h"G"G"GG "44T74KK " "fek22"z&,PS7T7T"!MMMMM "  "      4sB#B74B77 CCc<ddlm}t||}|d}t |t jrl|jdkrat|drQ|j |j krAd |j | j}t||t |t jrt| t |t$jr5t |jt*t,frt/|jSt |t$jt$jt$j|frt/|jSt |t$jrt/|jSt=||}|st|  t?| d|}nb#tB$r"}tEt-||d }~wtF$r+}tEd |$d |d }~wwxYw|%||} t | t jrt|| t?| d } t | t$jr| $dkr| jS| /t | tLj'r| (drdStEd| d)aInfer length of given node object. :param Union[nodes.ClassDef, nodes.Instance] node: :param node: Node to infer length of :raises AstroidTypeError: If an invalid node is returned from __len__ method or no __len__ method exists :raises InferenceError: If the given node cannot be inferred or if multiple nodes are inferred or if the code executed in python would result in a infinite recursive check for length :rtype int: Integer length of node r) FrozenSetr3T)future__len__rDzNSelf referential __len__ function will cause a RecursionError on line {} of {}N)r.zobject of type 'z' has no len())r.r/z builtins.int'z,' object cannot be interpreted as an integer))astroid.objectsrrlframer(r FunctionDefr+hasattrrDrformatlinenor*filerr r@rrrkbytesrrNListSetTupleeltsDictitemsrQrhrrir rpytyperrrU is_subtype_of) r.r/r inferred_node node_framemessage node_typelen_callrzrG result_of_lens r object_lenrs&*)))))tW555M4((J:|788 & Oy ( ( M: . . )  "j&7 7 7 66rsg  """"""%%%%%%FFFFFFFFFFFFFFFF99999999'&&&&&EEEEEEEE 2 2 2 2 IMPPPPP<IM,@D: M M M M M I I I I I"JN,( 0 0 0 01111 %%%% .MMMMMMMr"