
    c                    D   d Z ddlmZ ddlZddlmZmZ ddlmZ ddl	m
Z
 ddlmZmZmZ ddlmZ ej        d	k    rdd
l	mZ ndd
lmZ e
ej        ej        ej        ej        f         Z G d de          Z G d de          Zd!dZ eef          Z	 d"dZ	 d#d$d ZdS )%zHClasses representing different types of constraints on inference values.    )annotationsN)ABCabstractmethod)Iterator)Union)basesnodesutil)InferenceResult)      )Selfc                  ^    e Zd ZdZddZee	 ddd                        Zedd            ZdS )
Constraintz-Represents a single constraint on a variable.nodenodes.NodeNGnegateboolreturnNonec                $    || _         	 || _        d S )Nr   r   )selfr   r   s      2lib/python3.11/site-packages/astroid/constraint.py__init__zConstraint.__init__   s    	7QQ    Fcls
type[Self]
_NameNodesexprSelf | Nonec                    dS )zReturn a new constraint for node matched from expr, if expr matches
        the constraint pattern.

        If negate is True, negate the constraint.
        N )r   r   r    r   s       r   matchzConstraint.match!         r   inferredr   c                    dS )HReturn True if this constraint is satisfied by the given inferred value.Nr#   r   r&   s     r   satisfied_byzConstraint.satisfied_by,   r%   r   N)r   r   r   r   r   r   F
r   r   r   r   r    r   r   r   r   r!   r&   r   r   r   )	__name__
__module____qualname____doc__r   classmethodr   r$   r*   r#   r   r   r   r      s        77R R R R NS    ^ [ W W W ^W W Wr   r   c                  b    e Zd ZU dZ ej        d          Zded<   e	 ddd            Z	ddZ
dS )NoneConstraintz4Represents an "is None" or "is not None" constraint.Nznodes.Const
CONST_NONEFr   r   r   r   r    r   r   r   r   r!   c                &   t          |t          j                  rvt          |j                  dk    r^|j        }|j        d         \  }}|dv rCt          ||          r3t          || j                  r|dk    r|p|dk    o| } | ||          S dS )zReturn a new constraint for node matched from expr, if expr matches
        the constraint pattern.

        Negate the constraint based on the value of negate.
           r   >   isis notr8   r9   r   N)
isinstancer	   Comparelenopsleft_matchesr5   )r   r   r    r   r>   oprights          r   r$   zNoneConstraint.match6   s     dEM** 	5s48}}/A 	59DIB%% 5t$$5)1%)H)H5 */SR8^5RF
sV4444tr   r&   r   c                \    |t           j        u rdS | j        t          || j                  z  S )r(   T)r
   Uninferabler   r?   r5   r)   s     r   r*   zNoneConstraint.satisfied_byJ   s4     t'' 	4 {Xh@@@@r   r+   r,   r-   )r.   r/   r0   r1   r	   Constr5   __annotations__r2   r$   r*   r#   r   r   r4   r4   1   sy         >>)ek$//J////NS    [&A A A A A Ar   r4   r    r   framenodes.LocalsDictNodeNGr   dict[nodes.If, set[Constraint]]c                T   | }i }|||ur|j         }t          |t          j                  rt|                    |          \  }}d}|dk    r#t          t          | |j                            }n*|dk    r$t          t          | |j        d                    }|r|||<   |}|||u|S )aH  Returns the constraints for the given expression.

    The returned dictionary maps the node where the constraint was generated to the
    corresponding constraint(s).

    Constraints are computed statically by analysing the code surrounding expr.
    Currently this only supports constraints generated from if conditions.
    NbodyorelseT)invert)parentr:   r	   Iflocate_childset_match_constrainttest)r    rF   current_nodeconstraints_mappingrM   branch_constraintss           r   get_constraintsrX   T   s     )-L;=
 |5'@ $feh'' 		:++L99IFA26K U!"3D&+"F"FGG8# U!"3D&+d"S"S"STT :.9#F+  |5'@  r   node1nodes.NodeNG | bases.Proxynode2r   r   c                   t          | t          j                  r*t          |t          j                  r| j        |j        k    S t          | t          j                  rDt          |t          j                  r*| j        |j        k    ot          | j        |j                  S t          | t          j                  r*t          |t          j                  r| j	        |j	        k    S dS )z$Returns True if the two nodes match.F)
r:   r	   Namename	Attributeattrnamer?   r    rD   value)rY   r[   s     r   r?   r?   v   s    %$$ (E5:)F)F (zUZ''%)) Uj.P.P U~/THUZ4T4TT%%% **UEK*H*H *{ek))5r   Fr   rL   Iterator[Constraint]c              #  X   K   t           D ]}|                    | ||          }|r|V   dS )z3Yields all constraint patterns for node that match.N)ALL_CONSTRAINT_CLASSESr$   )r   r    rL   constraint_cls
constraints        r   rQ   rQ      sM       1  #))$f==
 	 r   )r    r   rF   rG   r   rH   )rY   rZ   r[   r   r   r   r+   )r   r   r    r   rL   r   r   rb   ) r1   
__future__r   sysabcr   r   collections.abcr   typingr   astroidr   r	   r
   astroid.typingr   version_infor   typing_extensions
AssignAttrr_   
AssignNamer]   r   r   r4   rX   	frozensetrd   r?   rQ   r#   r   r   <module>rs      s  
 O N " " " " " " 



 # # # # # # # # $ $ $ $ $ $       & & & & & & & & & & * * * * * *w '&&&&&&5#U_e6F
RS
W W W W W W W W2 A  A  A  A  AZ  A  A  AF   < #N#455  %	 	 	 	 :?      r   