
    c              	      
   U d Z ddlmZ ddlZddlZddlZddlZddlZddlm	Z	m
Z
mZmZ ddlmZmZmZmZmZ ddlmZmZmZmZmZmZmZ ddlmZ ddlmZmZmZm Z  dd	l!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z* dd
l+m,Z, ddl-m.Z. ddl/m0Z0m1Z1m2Z2 erddl3m4Z4  ej5        d          Z6 ed          Z7 edej8                  Z9 edej:                  Z;ej	        e1ee1         eej<        ej=        f         e1ee1         eegdf         Z>	 dddZ?e?ej@        _A        e?ejB        _A        e?ejC        _A        e?ejD        _A        e?ejE        _A        	 dddZFejG        	 ddd             ZHeHejI        _A        eHejJ        _A        eHejK        _A        	 ddd#ZLdd'ZMdd(ZNeLejO        _A        dd+ZP	 ddd.ZQ ejG         ejR        eQ                    ejS        _A        eQejT        _U        ejG        ejR        	 ddd1                        ZVeVejW        _A        ejG        ejR        	 	 ddd7                        ZXeXejY        _A        ejG        ejR        	 	 ddd9                        ZZeZej[        _A        	 ddd;Z\ ejG         ejR        e\                    ej]        _A         ejG        e\          ej^        _U        ejG        ejR        	 ddd=                        Z_e_ej`        _A         ea            Zb	 ddd@Zc ejG         ejR        ec                    ejd        _A         ejG        ec          ejd        _U        ejG        ejR        	 dddB                        Zeeeejf        _A        ddGZg	 dddJZhejG        ejR        	 dddK                        Ziehejj        _h        eiejj        _A        ddLZkddRZlddYZm	 ddd^Zn	 ddd_ZoddcZpdd ZqddeZrddkZsddmZtddqZu	 dddsZvejw        ejR        	 dddt                        Zxevej=        _v        exej=        _A        ejy        ejz        ej{        ej|        ej}        ej~        du dv dwZdxedy<   dzd{hZdd|ZddZ	 dddZeej        _A        	 dddZejG        ejR        	 ddd                        Zeej<        _        eej<        _A        ejG        	 ddd            Zeej        _A        ejG        ejR        	 ddd                        ZeejT        _A        eej^        _A        ejG        ejR        	 ddd                        Zeej        _A        ddZejG        	 ddd            Zeej        _A        	 dddZeej:        _A        dS )zMThis module contains a set of functions to handle inference on astroid trees.    )annotationsN)Callable	GeneratorIterableIterator)TYPE_CHECKINGAnyOptionalTypeVarUnion)bases
constraint
decoratorshelpersnodes	protocolsutil)
PY310_PLUS)CallContextInferenceContextbind_context_to_nodecopy_context)	AstroidBuildingErrorAstroidErrorAstroidIndexErrorAstroidTypeErrorAstroidValueErrorAttributeInferenceErrorInferenceErrorNameInferenceError_NonDeducibleTypeHierarchy)dunder_lookup)AstroidManager)InferenceErrorInfoInferenceResultSuccessfulInferenceResult)Propertyobjects_T_BaseContainerT)bound_FunctionDefT?list[functools.partial[Generator[InferenceResult, None, None]]]selfcontextInferenceContext | Nonekwargsr	   returnIterator[_T]c              +     K   | V  dS )zInference's end for nodes that yield themselves on inference.

    These are objects for which inference does not have any semantic,
    such as Module or Consts.
    N r.   r/   r1   s      1lib/python3.11/site-packages/astroid/inference.py	infer_endr8   F   s       JJJJJ    nodelist[SuccessfulInferenceResult]c                   g }| j         D ] }t          |t          j                  rqt	          j        |j        |          }|st          | |          t          |d          st          | |          |	                    t          |                     t          |t          j                  rCt	          j        |j        |          }|st          | |          |                    |           |                    |           |S )z.Infer all values based on _BaseContainer.elts.r:   r/   elts)r>   
isinstancer   Starredr   
safe_infervaluer   hasattrextend_infer_sequence_helper	NamedExprappend)r:   r/   valueseltstarredrB   s         r7   rE   rE   Z   s    Fy  c5=)) 	(G<<G A$$@@@@7F++ A$$@@@@MM099::::U_-- 	&sy'::E A$$@@@@MM%    MM#Mr9   Iterator[_BaseContainerT]c              +     K   t          d | j        D                       }|rUt          | |          } t          |           | j        | j        | j                  }|                    |           |V  d S | V  d S )Nc              3  b   K   | ]*}t          |t          j        t          j        f          V  +d S N)r?   r   r@   rF   ).0es     r7   	<genexpr>z!infer_sequence.<locals>.<genexpr>x   sF       ! !<=
1u}eo677! ! ! ! ! !r9   )lineno
col_offsetparent)anyr>   rE   typerR   rS   rT   postinit)r.   r/   r1   has_starred_named_exprrH   new_seqs         r7   infer_sequencerZ   r   s       ! ! !AE! ! !    	'g66$t**;4?4;
 
 
 	   




r9   
nodes.DictIterator[nodes.Dict]c              #  4  K   t          d | j        D                       s| V  d S t          | |          } t          |           | j        | j        | j                  }|                    t          |                                                     |V  d S )Nc              3  P   K   | ]!\  }}t          |t          j                  V  "d S rN   )r?   r   
DictUnpack)rO   k_s      r7   rQ   zinfer_map.<locals>.<genexpr>   s3      FF41az!U-..FFFFFFr9   )	rU   items
_infer_maprV   rR   rS   rT   rW   list)r.   r/   rb   rY   s       r7   	infer_mapre      s       FF4:FFFFF 




4))$t**T[$/4;GGekkmm,,---r9   lhs_dict:dict[SuccessfulInferenceResult, SuccessfulInferenceResult]rhs_dictc                    t          j        |                                 |                                          }d |D             }t          |                                          S )a  Delete nodes that equate to duplicate keys.

    Since an astroid node doesn't 'equal' another node with the same value,
    this function uses the as_string method to make sure duplicate keys
    don't get through

    Note that both the key and the value are astroid nodes

    Fixes issue with DictUnpack causing duplicate keys
    in inferred Dict items

    :param lhs_dict: Dictionary to 'merge' nodes into
    :param rhs_dict: Dictionary with nodes to pull from
    :return : merged dictionary of nodes
    c                B    i | ]\  }}|                                 ||fS r5   )	as_string)rO   keyrB   s      r7   
<dictcomp>z,_update_with_replacement.<locals>.<dictcomp>   s*    PPPJC#--//C<PPPr9   )	itertoolschainrb   dictrH   )rf   rh   combined_dict
string_maps       r7   _update_with_replacementrs      sV    & OHNN$4$4hnn6F6FGGMPP-PPPJ
!!##$$$r9   c                    i }| j         D ]\  }}t          |t          j                  rjt	          j        ||          }|st          t          |t          j                  st          | |          t          ||          }t          ||          }t	          j        ||          }t	          j        ||          }t          d ||fD                       rt          | |          t          |||i          }|S )z%Infer all values based on Dict.items.r=   r/   c              3     K   | ]}| V  d S rN   r5   )rO   elems     r7   rQ   z_infer_map.<locals>.<genexpr>   s$      ::t8::::::r9   )rb   r?   r   r_   r   rA   r   Dictrc   rs   rU   )	r:   r/   rH   namerB   double_starredunpack_itemsrl   
safe_values	            r7   rc   rc      s    JLFz I IedE,-- 	I$/w??N! %$$nej99 A$$@@@@%ng>>L-flCCFF$T7;;;C +E7CCCJ::j(9::::: A$$@@@@-fsJ6GHHFFMr9   nodes.NodeNGnodes.FunctionDef | Nonec                    | }|j         rLt          |j         t          j                  s-|j         }|j         rt          |j         t          j                  -|r|j         r|j         S dS )a  Search for the first function which encloses the given
    scope. This can be used for looking up in that function's
    scope, in case looking up in a lower scope for a particular
    name fails.

    :param node: A scope node.
    :returns:
        ``None``, if no parent function scope was found,
        otherwise an instance of :class:`astroid.nodes.scoped_nodes.Function`,
        which encloses the given node.
    N)rT   r?   r   FunctionDef)r:   currents     r7   _higher_function_scoper      sp     G
. !GNE<M!N!N !. . !GNE<M!N!N ! 7> ~4r9   nodes.Name | nodes.AssignName&Generator[InferenceResult, None, None]c                   |                      | j                  \  }}|skt          |                                           }|r|                     | j                  \  }}|s)t	          | j        |                                 |          t          |          }| j        |_        t          j        | |          |j	        | j        <   t          j        |||          S )z$Infer a Name: use name lookup rules.)ry   scoper/   )lookupry   r   r   r    r   
lookupnamer   get_constraintsconstraintsr   _infer_stmts)r.   r/   r1   framestmtsparent_functionra   s          r7   
infer_namer      s     ;;ty))LE5 
 1>> 	9&--di88HAu 	$YdjjllG    7##GG%/%?e%L%LG	"eWe444r9   
nodes.Call4Generator[InferenceResult, None, InferenceErrorInfo]c              +    K   t          |          }d|_        |'t          | |                                          |_        | j                            |          D ]t}|t          j        u r|V  	 t          |d          r>t          | j        | j        |          |_        |                    | |          E d{V  e# t          $ r Y qw xY wt!          | |          S )z?Infer a Call node by trying to guess what the function returns.Ninfer_call_result)argskeywordscallee)callerr/   r=   )r   	boundnode_populate_context_lookupcloneextra_contextfuncinferr   UninferablerC   r   r   r   callcontextr   r   r$   )r.   r/   r1   r   r   s        r7   
infer_callr     s      w''K K T$<T7==??$S$S!)//'**  T%% 	LLL	v233 V*5T]6+ + +' "3343UUUUUUUUU 	 	 	H	49999s   2AC
CCTnodes.Importasnamebool#Generator[nodes.Module, None, None]c              +  2  K   |pt                      }|j        }|t          | |          	 |r,|                     |                     |                    V  dS |                     |          V  dS # t
          $ r}t          | |          |d}~ww xY w)z8Infer an Import node: return the imported module/object.Nr=   )r   r   r   do_import_module	real_namer   )r.   r/   r   r1   ry   excs         r7   infer_importr      s       +)++GD 9$8888B 	.''t(<(<=======''------- B B B$888cABs   ,A5 A5 5
B?BBnodes.ImportFromc                X   |pt                      }|j        }|t          | |          |r;	 |                     |          }n$# t          $ r}t          | |          |d}~ww xY w	 |                                 }n$# t          $ r}t          | |          |d}~ww xY w	 t          |          }||_        |                    ||| 	                                u           }t          j        ||          S # t          $ r&}t          t          |          | ||          |d}~ww xY w)z;Infer a ImportFrom node: return the imported module/object.Nr=   )ignore_localstarget	attributer/   )r   r   r   r   r   r   r   r   getattrrootr   r   str)	r.   r/   r   r1   ry   r   moduler   errors	            r7   infer_import_fromr   :  sz    +)++GD 9$8888 F	F>>$''DD& 	F 	F 	F dG<<<#E	FB&&(( B B B$888cABw''!t6TYY[[3HII!%111"   JJttW
 
 
	sH   A 
A%A  A%)A> >
BBB#AC9 9
D)!D$$D)"nodes.Attribute | nodes.AssignAttrc              +  @  K   | j                             |          D ]}|t          j        u r|V  t	          |          }|j        }	 ||_        t          |t          j        t          j
        f          rFt          |t          j                  r|n|j        }t          j        | |          |j        | j        <   |                    | j        |          E d{V  n# t"          t$          t&          f$ r Y nw xY w||_        # ||_        w xY wt)          | |          S )zBInfer an Attribute node by using getattr on the associated object.)r   Nr=   )exprr   r   r   r   r   r?   r   ClassDefr   Instance_proxiedr   r   r   attrnameigetattrr   r   AttributeErrorr$   )r.   r/   r1   ownerold_boundnoder   s         r7   infer_attributer   `  sN      )) . .D$$ 	KKKw'')	. %G%%.%.!ABB !+E5>!B!BV5?5O6 6 6#DM2 ~~dmW==========#
 	 	 	
 D	 !.GG----49999s+   	BCDC85D7C88D	Dnodes.Globalc                &   ||j         t          | |          	 t          j        |                                                     |j                   |          S # t          $ r+}t          t          |          | |j         |          |d }~ww xY w)Nr=   r   )r   r   r   r   r   r   r   r   )r.   r/   r1   r   s       r7   infer_globalr     s    
  9', 9$8888!$))++"5"5g6H"I"I7SSS"   JJtw/A7
 
 
	s   >A 
B%&BBnodes.Subscript;Generator[InferenceResult, None, InferenceErrorInfo | None]c           	   +  ,  K   d}| j                             |          D ]`}|t          j        u rt          j        V   dS | j                            |          D ]"}|t          j        u rt          j        V    dS t
          }|j        t          j        k    r|}n0|j        t          j        k    rt          j
        |          }|r|}n|}|t
          u rt          | |          	 |                    ||          }n=# t          t          t          t           t"          f$ r}	t          | |          |	d}	~	ww xY w| |u s|t          j        u rt          j        V    dS |                    |          E d{V  d}$b|rt%          | |          S dS )zInference for subscripts.

    We're understanding if the index is a Const
    or a slice, passing the result of inference
    to the value's `getitem` method, which should
    handle each supported index type accordingly.
    FNr=   T)rB   r   r   r   slice_SUBSCRIPT_SENTINEL	__class__r   r   r   class_instance_as_indexr   getitemr   r   r   r   r   r$   )
r.   r/   r1   	found_onerB   indexindex_valueinstance_as_indexassignedr   s
             r7   infer_subscriptr     s      I!!'** ( (D$$ 	""""44Z%%g.. $	 $	E(( &&&&ttt .K%.0 $#EN2 $$+$CE$J$J!$ 4"3K#11 A$$@@@@	J ==g>> !!' J J J %$@@@cIJ x 8t/?#? &&&&ttt~~g.........III$	L  >!tW====4s   (C??#D9"D44D9nodes.BoolOpc              +  &  K   | j         }| j        dk    rt          j        }nt          j        }	 fd|D             }n# t
          $ r t          j        V  Y dS w xY wt          j	        | D ]}t          d |D                       rt          j        V  *d |D             }t          d |D                       rt          j        V  ^t          j        }t          ||          D ]\  }}	 ||	          r|V   n|V  t          |           S )zInfer a boolean operation (and / or / not).

    The function will calculate the boolean operation
    for all pairs generated through inference for each component
    node.
    orc                <    g | ]}|                                S )ru   )r   )rO   rB   r/   s     r7   
<listcomp>z!_infer_boolop.<locals>.<listcomp>  s'    LLLE5;;w;77LLLr9   Nc              3  2   K   | ]}|t           j        u V  d S rN   r   r   rO   items     r7   rQ   z _infer_boolop.<locals>.<genexpr>  s*      99Dtt''999999r9   c                6    g | ]}|                                 S r5   )
bool_valuer   s     r7   r   z!_infer_boolop.<locals>.<listcomp>  s"    :::Tt((:::r9   c              3  2   K   | ]}|t           j        u V  d S rN   r   r   s     r7   rQ   z _infer_boolop.<locals>.<genexpr>  s*      @@Dtt''@@@@@@r9   r=   )rH   opoperatortruthnot_r   r   r   rn   productrU   zipr$   )
r.   r/   r1   rH   	predicateinferred_valuespairbool_valuesrB   r   s
    `        r7   _infer_boolopr     sy      [Fw$ "N		M	LLLLVLLL   tt !?3  99D99999 	""""::T:::@@K@@@@@ 	""""  !$T;!7!7 	 	E:y$$  KKK49999s   ? AAinfer_callablejCallable[[_T, InferenceContext | None], Generator[InferenceResult | util.BadOperationMessage, None, None]]r   type[util.BadOperationMessage]c              #  n   K    || |          D ]%}t          ||          rt          j        V  !|V  &d S rN   )r?   r   r   )r.   r   r/   r   results        r7   _filter_operation_errorsr     s^       !.w//  fe$$ 	 """""LLLL r9   nodes.UnaryOpFGenerator[InferenceResult | util.BadUnaryOperationMessage, None, None]c              #    K   | j                             |          D ]^}	 |                    | j                  V  !# t          $ r'}t          j        || j        |          V  Y d}~Md}~wt          $ r}t          j	        | j                 }|K|
                                }|t
          j        urt          j        |           V  nt
          j        V  nt          |t          j        t          j        f          s#t          j        || j        |          V  Y d}~	 	 t%          j        ||          }n2# t(          $ r% t          j        || j        |          V  Y Y d}~Nw xY w|d         }t+          |                    |          d          }|t
          j        u s|                                sY d}~t/          |          }||_        t3          g |          |_        |                    | |          }t+          |d          }	|	|V  n|	V  nM# t(          $ r'}
t          j        || j        |
          V  Y d}
~
n!d}
~
wt8          $ r t
          j        V  Y nw xY wY d}~Xd}~ww xY wdS )3Infer what an UnaryOp should return when evaluated.Nr   ru   )r   r   )operandr   infer_unary_opr   	TypeErrorr   BadUnaryOperationMessager   r   UNARY_OP_METHODr   r   r   const_factoryr?   r   r   r   r"   r   r   nextcallabler   r   r   r   r   r   )r.   r/   r   r   methr   methodsinferredcall_resultsr   	inner_excs              r7   _infer_unaryopr  1  s      <%%g.. 3+ 3+2	+((111111 	G 	G 	G/#FFFFFFFFFF -	+ -	+ -	+,TW5D ++ %//11
T%55 +-*n======*****!'ENEN+KLL  7#NNNNNHHHH+!"/"6w"E"E2 ! ! !";GTWcRRRRR ! #1:D#DJJwJ$?$?FFH4#33 !8;L;L;N;N ! *733G(/G%*52h*O*O*OG'#+#=#=dG#=#T#TL!,55F %%$. U U U7)TTTTTTTTTT% + + +******+Y-	+3+ 3+s~   >
I:A**I:8B'I5'D=<H"='E,$H"+E,,AH"AH"!I5"
I,,I	I5I,)I5+I,,I55I:c              +  v   K   t          | t          |t          j                  E d{V  t	          | |          S )r   Nr=   )r   r  r   r   r$   r6   s      r7   infer_unaryopr  k  sY       (ngt'D         49999r9   c                R    t          | t          j                  o| j        t          u S )z0Check if the given const node is NotImplemented.)r?   r   ConstrB   NotImplemented)consts    r7   _is_not_implementedr  {  s     eU[))Kek^.KKr9   instancenodes.Constotherr   +tuple[type[util.Uninferable] | nodes.Const]c                t   t          |t          j                  rit          j        |j        v rt          j        fS fd|j        D             }t          d |D                       rt          d |D                       }nd}nt          |t          j                  ri }|j	        D ]}t          j        |d                   }t          |t          j                  st          j        fc S t          j        |d                   }t          |t          j                  st          j        fc S |j        ||j        <   n/t          |t          j                  r|j        }nt          j        fS 	 t          j        | j        |z            fS # t          t           t"          f$ r t          j        fcY S w xY w)zInfer the result of '"string" % ...'.

    TODO: Instead of returning Uninferable we should rely
    on the call to '%' to see if the result is actually uninferable.
    c                :    g | ]}t          j        |          S r5   )r   rA   )rO   ir/   s     r7   r   z6_infer_old_style_string_formatting.<locals>.<listcomp>  s&    RRR!w1!W==RRRr9   c              3  J   K   | ]}t          |t          j                  V  d S rN   )r?   r   r  rO   r  s     r7   rQ   z5_infer_old_style_string_formatting.<locals>.<genexpr>  s.      GGaz!U[))GGGGGGr9   c              3  $   K   | ]}|j         V  d S rN   )rB   r  s     r7   rQ   z5_infer_old_style_string_formatting.<locals>.<genexpr>  s$      @@q17@@@@@@r9   Nr      )r?   r   Tupler   r   r>   alltuplerx   rb   r   rA   r  rB   r   r   KeyError
ValueError)r	  r  r/   inferred_positionalrH   r   rl   rB   s     `     r7   "_infer_old_style_string_formattingr    s    %%% #uz) 	'$&&RRRRuzRRRGG3FGGGGG 	@@,?@@@@@FFFF	E5:	&	& #!#K 	, 	,D$T!Wg66Cc5;// +(****&tAw88EeU[11 +(**** %F39	, 
E5;	'	' # ""##HNV$;<<>>x, # # # """"#s   3F $F76F7r%   opnodenodes.AugAssign | nodes.BinOpr   r   method_namec                   t          j        | |          }t          ||           }|d         }||j        _        t          | t          j                  r>t          | j        t                    r$|dk    rt          t          | ||                    S 	 t          |                    |                    }n$# t          $ r}	t          ||          |	d}	~	ww xY w|t           j        u rt          t          | t          j        t          j        t          j        t          j        t*          j        f          st          |                     |||||          S )z8Invoke binary operation inference on the given instance.r   %ru   r=   N)r"   r   r   r   r   r?   r   r  rB   r   iterr  r   r   StopIterationr   r   r   r  Listr   r   r   infer_binary_op)
r	  r  r   r  r/   r  r   methodr   rP   s
             r7   _invoke_binop_inferencer%    sR    "8[99G"7H55GQZF!'G 	8U[))Rx~s++R #IR
 6xPPQQQBW5566 B B B&':::AB4## 5;UZX   ##FBwIIIs   #B7 7
CCCFnodes.AugAssignreverse9functools.partial[Generator[InferenceResult, None, None]]c           	     f    t           j        |         }t          j        t          | |||||          S )z<Get an inference callable for an augmented binary operation.r	  r   r  r  r/   r  )r   AUGMENTED_OP_METHOD	functoolspartialr%  r	  r  r   r  r/   r'  r  s          r7   _aug_opr/    s@     /3K   r9   c           	         |rt           j        |         }nt           j        |         }t          j        t
          | |||||          S )zGet an inference callable for a normal binary operation.

    If *reverse* is True, then the reflected method will be used instead.
    r*  )r   REFLECTED_BIN_OP_METHODBIN_OP_METHODr,  r-  r%  r.  s          r7   _bin_opr3    sW      27;-b1   r9   left.bases.UnionType | nodes.ClassDef | nodes.Constrightc              #  8   K   t          j        | |          V  dS )z>Create a new UnionType instance for binary or, e.g. int | str.N)r   	UnionType)r4  r6  s     r7   _bin_op_or_union_typer9    s&      
 /$
&
&&&&&&r9   c              #     K   ||fD ]7}|                                  }t          |g          |_        d|_        |V  8dS )zGet contexts for binary operations.

    This will return two inference contexts, the first one
    for x.__op__(y), the other one for y.__rop__(x), where
    only the arguments are inversed.
    )r   N)r   r   r   r   )r/   r4  r6  argnew_contexts        r7   _get_binop_contextsr=    s^       t}  mmoo"-C5"9"9"9 $	 r9   c                V    |                                  |                                 k    S )z$Check if type1 is the same as type2.)qname)type1type2s     r7   
_same_typerB    s    ;;==EKKMM))r9   	left_typeInferenceResult | Nonebinary_opnode
right_typereverse_contextc           	        |j         }t          ||          rt          | ||||          g}nt          j        ||          rt          | ||||          g}nft          j        ||          r)t          |||| |d          t          | ||||          g}n(t          | ||||          t          |||| |d          g}t          r|dk    rt          | t          j	        t          j        f          s!t          | t          j                  r}| j        vt          |t          j	        t          j        f          s!t          |t          j                  r6|j        /|                    t          j        t"          | |          g           |S )aV  Get the flow for binary operations.

    The rules are a bit messy:

        * if left and right have the same type, then only one
          method will be called, left.__op__(right)
        * if left and right are unrelated typewise, then first
          left.__op__(right) is tried and if this does not exist
          or returns NotImplemented, then right.__rop__(left) is tried.
        * if left is a subtype of right, then only left.__op__(right)
          is tried.
        * if left is a supertype of right, then right.__rop__(left)
          is first tried and then left.__op__(right)
    Tr'  |)r   rB  r3  r   
is_subtypeis_supertyper   r?   r   r8  r   r   r  rB   rD   r,  r-  r9  )	r4  rC  rE  r6  rF  r/   rG  r   r   s	            r7   _get_binop_flowrM    s   . 
	B)Z(( 
4E7CCD		Iz	2	2 
4E7CCD		i	4	4 	
E="dOTRRRD-UG<<
 D-UG<<E="dOTRRR
 	P#IP teou~>??	P
 $,,P 
P uu?@@P %--P P 		)*?uMMNOOONr9   
aug_opnodec           
     B   |j                             d          }|j         }t          ||          r't          | ||||          t	          | ||||          g}	nt          j        ||          r't          | ||||          t	          | ||||          g}	nt          j        ||          r;t          | ||||          t	          |||| |d          t	          | ||||          g}	n:t          | ||||          t	          | ||||          t	          |||| |d          g}	|	S )a  Get the flow for augmented binary operations.

    The rules are a bit messy:

        * if left and right have the same type, then left.__augop__(right)
          is first tried and then left.__op__(right).
        * if left and right are unrelated typewise, then
          left.__augop__(right) is tried, then left.__op__(right)
          is tried and then right.__rop__(left) is tried.
        * if left is a subtype of right, then left.__augop__(right)
          is tried and then left.__op__(right).
        * if left is a supertype of right, then left.__augop__(right)
          is tried, then right.__rop__(left) and then
          left.__op__(right)
    =TrI  )r   striprB  r/  r3  r   rK  rL  )
r4  rC  rN  r6  rF  r/   rG  bin_opaug_opr   s
             r7   _get_aug_flowrT  M  sS   0 ]  %%F]F)Z(( 
D*feW==D*feW==
 
	Iz	2	2 
D*feW==D*feW==
 
	i	4	4 
D*feW==E:vt_dSSSD*feW==
 D*feW==D*feW==E:vt_dSSS

 Nr9   flow_factoryGetFlowFactoryGGenerator[InferenceResult | util.BadBinaryOperationMessage, None, None]c           	   #    K   t          || |          \  }}t          j        |           }t          j        |          } || ||||||          }|D ]}		 t           |	                      }
t	          d |
D                       rt
          j        V   dS t          t          t          |
                    rgt          d |
D                       }|r$|t          |
          k    rt
          j        V   dS |
E d{V   dS # t          $ r Y t          $ r Y t          $ r t
          j        V  Y  dS w xY wt          j        ||j        |          V  dS )zInfer a binary operation between a left operand and a right operand.

    This is used by both normal binary operations and augmented binary
    operations, the only difference is the flow factory used.
    c              3  2   K   | ]}|t           j        u V  d S rN   r   rO   r   s     r7   rQ   z*_infer_binary_operation.<locals>.<genexpr>  s*      DD&6T--DDDDDDr9   Nc              3  8   K   | ]}t          |          d V  dS )r  N)r  rZ  s     r7   rQ   z*_infer_binary_operation.<locals>.<genexpr>  sD       " "+>v+F+F"" " " " " "r9   )r=  r   object_typerd   rU   r   r   r  mapr  sumlenr   r   r   BadBinaryOperationMessager   )r4  r6  rE  r/   rU  rG  rC  rF  r   r$  resultsnot_implementeds               r7   _infer_binary_operationrc    s       37D%HHG_#D))I$U++Jliz7O G   	6688nnG DDGDDDDD &&&&3*G4455 ! " " '" " "  O  ?c'll#B &&&&FF/  	 	 	H& 	 	 	H 	 	 	""""FFF	* 
(M4Dj
Q
QQQQQQs   D
D6	D6D65D6nodes.BinOpc              #    K   | j         }| j        }|pt                      }t          |          }t          |          }|                    |          }|                    |          }t          j        ||          D ]n\  }}	t          d |	|fD                       rt          j	        V   dS 	 t          ||	| |t                    E d{V  Q# t          $ r t          j	        V  Y kw xY wdS )z!Binary operation inference logic.ru   c              3  2   K   | ]}|t           j        u V  d S rN   r   rO   rB   s     r7   rQ   z_infer_binop.<locals>.<genexpr>  *      AAUu((AAAAAAr9   N)r4  r6  r   r   r   rn   r   rU   r   r   rc  rM  r!   )
r.   r/   r4  r6  lhs_contextrhs_contextlhs_iterrhs_iterlhsrhss
             r7   _infer_binopro    s,      9DJE
 +)++Gw''Kw''Kzz+z..H{{;{//H%h99 	# 	#SAAsCjAAAAA 	""""FF	#.sCwXXXXXXXXXX) 	# 	# 	#""""""	#	# 	#s   2CC,+C,c                D    t          | t          |t          j                  S rN   )r   ro  r   r`  r6   s      r7   infer_binoprq    s"    
 $lGT%C  r9   c                
    | |v S rN   r5   abs     r7   <lambda>rv    s
    qAv r9   c                
    | |vS rN   r5   rs  s     r7   rv  rv    s
    1A: r9   )z==z!=<z<=>z>=inznot inz%dict[str, Callable[[Any, Any], bool]]COMPARE_OPSiszis notc                N    t          j        |                                           S rN   )astliteral_evalrk   )r:   s    r7   _to_literalr    s     DNN,,---r9   	left_iterIterable[nodes.NodeNG]
right_iterbool | type[util.Uninferable]c                   d}|t           v rt          j        S t          |         }t	          j        | |          D ]\  }}|t          j        u s|t          j        u rt          j        c S 	 t          |          t          |          }}n+# t          t          t          f$ r t          j        cY c S w xY w	  |||          }n# t          $ r}t          |d}~ww xY w||}||k    rt          j        c S |J |S )aa  
    If all possible combinations are either True or False, return that:
    >>> _do_compare([1, 2], '<=', [3, 4])
    True
    >>> _do_compare([1, 2], '==', [3, 4])
    False

    If any item is uninferable, or if some combinations are True and some
    are False, return Uninferable:
    >>> _do_compare([1, 3], '<=', [2, 4])
    util.Uninferable
    N)UNINFERABLE_OPSr   r   r{  rn   r   r  SyntaxErrorr  r   r   r   )	r  r   r  retvalop_funcr4  r6  r   r   s	            r7   _do_comparer    sP    F	_  "oG (J?? $ $e4## 	$u0@'@ 	$####	$%d++[-?-?%DDZ8 	$ 	$ 	$######	$	,74''DD 	, 	, 	,"+	,  	$FFt^ 	$####	$ Ms*   *B		#B10B15C
CCCnodes.Compare;Generator[nodes.Const | type[util.Uninferable], None, None]c              +    K   d}| j         }| j        }t          |                    |                    }|D ]`\  }}t          |                    |                    }		 t	          |||	          }n# t
          $ r t          j        }Y  nw xY w|dur n|	}a|t          j        u r|V  dS t          j	        |          V  dS )z#Chained comparison inference logic.Tru   N)
opsr4  rd   r   r  r   r   r   r   r  )
r.   r/   r1   r  r  	left_noderm  r   
right_nodern  s
             r7   _infer_comparer    s       -1F
(C	I
yw//
0
0C 
 
J:##G#4455	 b#..FF 	 	 	%FEE	  	E!! "k&!!!!!!!s   !A33BBc              #    K   |pt                      }|                                }| j                            |          }| j                            |          }t          j        ||          D ]o\  }}t          d ||fD                       rt          j
        V   dS 	 t          ||| |t                    E d{V  R# t          $ r t          j
        V  Y lw xY wdS )z0Inference logic for augmented binary operations.ru   c              3  2   K   | ]}|t           j        u V  d S rN   r   rg  s     r7   rQ   z#_infer_augassign.<locals>.<genexpr>F  rh  r9   N)r4  r6  rE  r/   rU  )r   r   r   	infer_lhsrB   r   rn   r   rU   r   r   rc  rT  r!   )r.   r/   rj  rk  rl  rm  rn  s          r7   _infer_augassignr  ;  s9      +)++G--//K{$$W$55Hz44H%h99 # #SAAsCjAAAAA 	""""FF		#."*           * 	# 	# 	#""""""	## #s   $CCCc                D    t          | t          |t          j                  S rN   )r   r  r   r`  r6   s      r7   infer_augassignr  W  s#    
 $)G  r9   nodes.Argumentsc                l    ||j         t          | |          t          j        | |j         |          S )Nr=   )r   r   r   _arguments_infer_argnamer6   s      r7   infer_argumentsr  g  sA      9', 9$8888-dG4FPPPr9   #nodes.AssignName | nodes.AssignAttrc                    t          | j        t          j                  r| j                            |          S t          |                     |                    }t          j        ||          S )zXInfer a AssignName/AssignAttr: need to inspect the RHS part of the
    assign node.
    ru   )	r?   rT   r   	AugAssignr   rd   assigned_stmtsr   r   )r.   r/   r1   r   s       r7   infer_assignr  s  sa     $+u// *{  )))$$W$5566EeW---r9   nodes.EmptyNodec              +     K   |                                  st          j        V  d S 	 t                                          | j        |          E d {V  d S # t          $ r t          j        V  Y d S w xY w)Nru   )has_underlying_objectr   r   r#   infer_ast_from_somethingobjectr   r6   s      r7   infer_empty_noder    s      
 %%'' #	#%''@@W A             	# 	# 	#"""""""	#s   .A A43A4callc                    i }||S | j         D ],}t          |t          j                  r|||j        <   '|||<   -| j        | j        ng }|D ]}|||j        <   |S rN   )r   r?   r   r@   rB   r   )r  r/   context_lookupr;  r   keywords         r7   r   r     s     ?AN y * *c5=)) 	*(/N39%%")N3 $At}}rH 0 0(/w}%%r9   nodes.IfExpc              +  p  K   d}|pt                      }t          |          }t          |          }	 t          | j                            |                                                    }|t          j        urX|                                r"| j	                            |          E d{V  n>| j
                            |          E d{V  nd}n# t          t          f$ r d}Y nw xY w|rD| j	                            |          E d{V  | j
                            |          E d{V  dS dS )zSupport IfExp inference.

    If we can't infer the truthiness of the condition, we default
    to inferring both branches. Otherwise, we infer either branch
    depending on the condition.
    Fru   NT)r   r   r   testr   r   r   r   r   bodyorelser   r!  )r.   r/   r1   both_branchesri  rj  r  s          r7   infer_ifexpr    s      M
 +)++Gw''Kw''K!DIOOGMMOOO<<== t'' 	!   B9??;???????????;,,[,AAAAAAAAAA MM M*     :9??;?777777777;$$[$99999999999: :s   :C C-,C-=Generator[Property | _FunctionDefT, None, InferenceErrorInfo]c              +  r  K   | j         rt          j        |           s| V  t          | |          S | j                            d          }| j        |j        v o(t          d |j        | j                 D                       }t          | j        t          j        t          j        t          j        f          rd}t                              | | j        | j        |s| j        nd | j                  }|r| j        |_        |                    g | j        | j                   |V  t          | |          S )Nr=   T)futurec              3  J   K   | ]}t          |t          j                  V  d S rN   )r?   r(   r'   )rO   vals     r7   rQ   z$infer_functiondef.<locals>.<genexpr>  sH       Q Q.1
3())Q Q Q Q Q Qr9   )functionry   rR   rT   rS   )r  r   doc_node)r   r   _is_propertyr$   rT   r   ry   localsrU   r?   r   	TryExcept
TryFinallyIfr(   r'   rR   rS   rW   r   r  )r.   r/   r1   parent_frame!property_already_in_parent_locals	prop_funcs         r7   infer_functiondefr    s[      ? >%"4T":": >


!tW==== ;$$D$11L(,	\5H(H )S Q Q5A5H5SQ Q Q N N% $+1A58LMM 1,0)  Y{"CMt{{? !  I ) ';	BTYGGG
OOO49999r9   rN   )r.   r)   r/   r0   r1   r	   r2   r3   )r:   r*   r/   r0   r2   r;   )r.   r*   r/   r0   r1   r	   r2   rK   )r.   r[   r/   r0   r2   r\   )rf   rg   rh   rg   r2   rg   )r:   r[   r/   r0   r2   rg   )r:   r}   r2   r~   )r.   r   r/   r0   r1   r	   r2   r   )r.   r   r/   r0   r1   r	   r2   r   )NT)
r.   r   r/   r0   r   r   r1   r	   r2   r   )
r.   r   r/   r0   r   r   r1   r	   r2   r   )r.   r   r/   r0   r1   r	   r2   r   )r.   r   r/   r0   r1   r	   r2   r   )r.   r   r/   r0   r1   r	   r2   r   )r.   r   r/   r0   r1   r	   r2   r   )
r.   r)   r   r   r/   r0   r   r   r2   r   )r.   r   r/   r0   r2   r   )r.   r   r/   r0   r1   r	   r2   r   )r2   r   )r	  r
  r  r}   r/   r   r2   r  )r	  r%   r  r  r   r   r  r%   r/   r   r  r   r2   r   )F)r	  r%   r  r&  r   r   r  r%   r/   r   r'  r   r2   r(  )r	  r%   r  r  r   r   r  r%   r/   r   r'  r   r2   r(  )r4  r5  r6  r5  r2   r   )r4  r%   rC  rD  rE  r  r6  r%   rF  rD  r/   r   rG  r   r2   r-   )r4  r%   rC  rD  rN  r&  r6  r%   rF  rD  r/   r   rG  r   r2   r-   )r4  r%   r6  r%   rE  r  r/   r   rU  rV  r2   rW  )r.   rd  r/   r0   r2   rW  )r.   rd  r/   r0   r1   r	   r2   r   )r:   r}   r2   r	   )r  r  r   r   r  r  r2   r  )r.   r  r/   r0   r1   r	   r2   r  )r.   r&  r/   r0   r2   rW  )r.   r&  r/   r0   r1   r	   r2   r   )r.   r  r/   r0   r1   r	   r2   r   )r.   r  r/   r0   r1   r	   r2   r   )r.   r  r/   r0   r1   r	   r2   r   )r  r   r/   r0   )r.   r  r/   r0   r1   r	   r2   r   )r.   r,   r/   r0   r1   r	   r2   r  )__doc__
__future__r   r~  r,  rn   r   typingcollections.abcr   r   r   r   r   r	   r
   r   r   astroidr   r   r   r   r   r   r   astroid.constr   astroid.contextr   r   r   r   astroid.exceptionsr   r   r   r   r   r   r   r    r!   astroid.interpreterr"   astroid.managerr#   astroid.typingr$   r%   r&   astroid.objectsr'   lazy_importr(   r)   BaseContainerr*   r   r,   r  BinOprV  r8   Module_inferr   Lambdar  SlicerE   raise_if_nothing_inferredrZ   r"  r  Setre   rs   rc   rx   r   r   path_wrapperName
AssignNamer  r   Callr   Importr   
ImportFromr   	Attribute
AssignAttrr   Globalr  r   r   	Subscriptr   BoolOpr   r  r  UnaryOpr  r  r%  r/  r3  r9  r=  rB  rM  rT  rc  ro  yes_if_nothing_inferredrq  eqneltlegtger{  __annotations__r  r  r  r  Comparer  r  r  	Argumentsr  r  	EmptyNoder   r  IfExpr  r5   r9   r7   <module>r     s
  
 T S S " " " " " " 



           C C C C C C C C C C C C ? ? ? ? ? ? ? ? ? ? ? ? ? ? R R R R R R R R R R R R R R R R R R $ $ $ $ $ $           
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 . - - - - - * * * * * *           )(((((( $
9
%
%WT]]'+53FGGGu/@AAA!eou{*+! F	G" 26       !     ?C    0 % (,    &%( #
 # !	  :>	 	 	 	 	% % % %4   0 
    , (,5 5 5 5 58 9J8JJ'' 
  (   %9=: : : :  &%:0 
  % (,B B B B  &%B* #  % (,     &%B ,  
 (,: : : : :D >=JO,,   BZA/RR   %;?
 
 
 
  &%
 #  fhh  ?C8 8 8 8 8z >=JO,,   AJ@QQ  %;?2: 2: 2: 2:  &%2:j $    ( =A7+ 7+ 7+ 7+ 7+t %<@: : : :  &%:  . $ L L L L
"# "# "# "#JJ J J JP     6     6' ' ' '   * * * *
6 6 6 6r0 0 0 0f/R /R /R /Rf ;?# # # # #6 #:>     $# (    +
+	
+	
+

%%	6 	6 	 	 	 	 	. . . .) ) ) )Z =A" " " " "6 &  ?C# # # # #8 %>B     &% $4  ( 
 %>BQ Q Q Q &%Q )  % (,. . . .  &%. '  &   %>B# # # #  &%# *    " %:>: : : : &%:D !  =A: : : : :D -    r9   