o
    h{'                    @   s:  d Z ddlZddlZddlZddlZddlZddlZddl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 eedZeeZe
 jZdd ZejejfZdd Zd	d
 Zdd Zdd Zdd Ze	dZ e	dZ!e	dZ"e	dZ#e	dZ$e%dZ&dd Z'dd Z(G dd de)Z*dd Z+de* fdd Z,d!d" Z-d#d$ Z.G d%d& d&Z/G d'd( d(e/Z0G d)d* d*e0Z1G d+d, d,Z2G d-d. d.Z3G d/d0 d0e0Z4G d1d2 d2e4Z5G d3d4 d4e4Z6G d5d6 d6e4Z7G d7d8 d8e6Z8G d9d: d:e/Z9G d;d< d<e/Z:G d=d> d>e:Z;G d?d@ d@e/Z<G dAdB dBe0Z=G dCdD dDe0Z>G dEdF dFe/Z?G dGdH dHe)Z@G dIdJ dJe@ZAG dKdL dLe@ZBG dMdN dNe@ZCG dOdP dPe@ZDG dQdR dRe@ZEG dSdT dTeEZFG dUdV dVZGg dWZHdXdY ZIe%dZZJd[d\ ZKd]d^ ZLd_d` ZMdadb ZNG dcdd ddZOdedf ZPdgdh ZQG didj djZRdS )kz]
Main module.

Implement the central Checker class.
Also, it models the Bindings and Scopes.
    N)messagespypy_version_infoc                 C   sl   t | tjr
| jgS t | tjr| j| j gdd | jD  S tjdkr2t | tj	r4dd | j
D S d S d S )Nc                 S   s   g | ]}|gqS  r   ).0hdlr   r   F/var/www/html/ai/venv/lib/python3.10/site-packages/pyflakes/checker.py
<listcomp>!       z#getAlternatives.<locals>.<listcomp>)   
   c                 S      g | ]}|j qS r   )body)r   mcr   r   r   r   #   r	   )
isinstanceastIfr   Tryorelsehandlerssysversion_infoMatchcases)nr   r   r   getAlternatives   s   r   c                 C   s&   t | tjot | jttttd fS N)r   r   ConstantvaluebooltypeEllipsisnoder   r   r   _is_singleton)   s   r#   c                 C   s    t | tjotdd | jD S )Nc                 s       | ]}t |V  qd S r   )_is_constantr   eltr   r   r   	<genexpr>3       z%_is_tuple_constant.<locals>.<genexpr>)r   r   Tuplealleltsr!   r   r   r   _is_tuple_constant0   s   r-   c                 C   s   t | tjp	t| S r   )r   r   r   r-   r!   r   r   r   r%   7   s   r%   c                 C   s   t | ot|  S r   )r%   r#   r!   r   r   r   _is_const_non_singleton;      r.   c                 C   s,   t | tjr| j|kpt | tjo| j|kS r   )r   r   Nameid	Attributeattr)r"   namer   r   r   _is_name_or_attr?   s   r5   z\(([^()]*)\)z[#0+ -]*z
(?:\*|\d*)z(?:\.(?:\*|\d*))?z[hlL]?zdiouxXeEfFgGcrsa%c                 C   s   |  ||}|d usJ |S r   )match)regexstringposr6   r   r   r   _must_matchO   s   r:   c                    s    fdd}t | S )zParses the string component of a `'...' % ...` format call

    Copied from https://github.com/asottile/pyupgrade at v1.20.1
    c                  3   st   d} d}d}d}|t  k r|s6z d|}W n ty,    | d  d fV  Y d S w |}|d7 }d}nvt |}|rH|d}| }nd }tt |}| pUd }| }tt	 |}| ped }	| }tt
 |}
|
 pud }|
 }tt | }z | }W n ty   tdw |d7 }|||	||f} | | |fV  d}|} |t  k s|rtdd S )Nr   F%   Tz"end-of-string while parsing format)lenindex
ValueErrorMAPPING_KEY_REr6   groupendr:   CONVERSION_FLAG_REWIDTH_REPRECISION_RE	LENGTH_RE
IndexError)string_start
string_endin_fmti	key_matchkeyconversion_flag_matchconversion_flagwidth_matchwidthprecision_match	precision
conversionfmtsr   r   _parse_inner[   sZ   

.z*parse_percent_format.<locals>._parse_inner)tuple)rW   rX   r   rV   r   parse_percent_formatU   s   
7rZ   c                   @   s    e Zd ZdZdd Zdd ZdS )_FieldsOrderzFix order of AST node fields.c                 C   s>   |j }d|v rdj}nd|v rdj}ndj}tt||ddS )Niter
generatorsr   T)rM   reverse)_fieldsfindrY   sorted)self
node_classfields	key_firstr   r   r   _get_fields   s   z_FieldsOrder._get_fieldsc                 C   s   |  | | |< }|S r   )rf   )rb   rc   rd   r   r   r   __missing__   s   z_FieldsOrder.__missing__N)__name__
__module____qualname____doc__rf   rg   r   r   r   r   r[      s    r[   c                 C   s&   i }| D ]}| |dd ||< q|S )z|
    Simplest required implementation of collections.Counter. Required as 2.6
    does not have Counter in collections.
    r   r<   )get)itemsresultsitemr   r   r   counter   s   rp   c                 c   sj    || j  D ],}|r||v rqt| |d}t|tjr|V  qt|tr2|D ]}t|tjr1|V  q&qdS )a  
    Yield all direct child nodes of *node*, that is, all fields that
    are nodes and all items of fields that are lists of nodes.

    :param node:          AST node to be iterated upon
    :param omit:          String or tuple of strings denoting the
                          attributes of the node to be omitted from
                          further parsing
    :param _fields_order: Order of AST node fields
    N)	__class__getattrr   r   ASTlist)r"   omit_fields_orderr4   fieldro   r   r   r   iter_child_nodes   s   
rx   c                 C   sN   t | tjr	| jS t | tjrtdd | jD S t | tjr$t| dS t	 S )Nc                 s   r$   r   convert_to_value)r   rK   r   r   r   r(      r)   z#convert_to_value.<locals>.<genexpr>ro   )
r   r   r   r   r*   rY   r,   r0   VariableKeyUnhandledKeyTyper{   r   r   r   rz      s   
rz   c                 C   s   t | tjot| dkS )NNotImplemented)r   r   r0   getNodeNamer!   r   r   r   is_notimplemented_name_node   s   r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )Bindingar  
    Represents the binding of a value to a name.

    The checker uses this to keep track of which names have been bound and
    which names have not. See L{Assignment} for a special type of binding that
    is checked with stricter rules.

    @ivar used: pair of (L{Scope}, node) indicating the scope and
                the node that this binding was last used.
    c                 C   s   || _ || _d| _d S NF)r4   sourceusedrb   r4   r   r   r   r   __init__   s   
zBinding.__init__c                 C      | j S r   )r4   rb   r   r   r   __str__      zBinding.__str__c                 C   s   d | jj| j| jjt| S )Nz)<{} object {!r} from line {!r} at 0x{:x}>)formatrq   rh   r4   r   linenor1   r   r   r   r   __repr__   s   zBinding.__repr__c                 C   s   t |to
| j|jkS r   )r   
Definitionr4   rb   otherr   r   r   	redefines      zBinding.redefinesN)rh   ri   rj   rk   r   r   r   r   r   r   r   r   r      s    r   c                           e Zd ZdZ fddZ  ZS )r   z7
    A binding that defines a function or a class.
    c                    s"   t  |pt|to| j|jkS r   )superr   r   
Assignmentr4   r   rq   r   r   r      s   zDefinition.redefines)rh   ri   rj   rk   r   __classcell__r   r   r   r   r      s    r   c                       s(   e Zd ZdZ fddZdd Z  ZS )Builtinz-A definition created for all Python builtins.c                    s   t  |d  d S r   )r   r   )rb   r4   r   r   r   r     r/   zBuiltin.__init__c                 C   s   d | jj| jt| S )Nz<{} object {!r} at 0x{:x}>)r   rq   rh   r4   r1   r   r   r   r   r   
  s
   zBuiltin.__repr__)rh   ri   rj   rk   r   r   r   r   r   r   r   r     s    r   c                   @      e Zd ZdZdS )r}   zS
    A dictionary key of a type that we cannot or do not check for duplicates.
    Nrh   ri   rj   rk   r   r   r   r   r}         r}   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	r|   zY
    A dictionary key which is a variable.

    @ivar item: The variable AST object.
    c                 C   s   |j | _d S r   )r1   r4   )rb   ro   r   r   r   r     s   zVariableKey.__init__c                 C   s   |j | j ko|j| jkS r   )rq   r4   )rb   comparer   r   r   __eq__!  s   
zVariableKey.__eq__c                 C   s
   t | jS r   )hashr4   r   r   r   r   __hash__'  s   
zVariableKey.__hash__N)rh   ri   rj   rk   r   r   r   r   r   r   r   r|     s
    r|   c                       sF   e Zd ZdZd fdd	Zdd Zdd Zed	d
 Zdd Z	  Z
S )Importationz
    A binding created by an import statement.

    @ivar fullName: The complete name given to the import statement,
        possibly including multiple dotted components.
    @type fullName: C{str}
    Nc                    s"   |p|| _ g | _t || d S r   )fullName	redefinedr   r   )rb   r4   r   	full_namer   r   r   r   4  s   
zImportation.__init__c                 C   s,   t |tr| j|jkS t |to| j|jkS r   )r   SubmoduleImportationr   r   r4   r   r   r   r   r   9  s   
zImportation.redefinesc                 C   s   | j dd | jk S )z.Return whether importation needs an as clause..)r   splitr4   r   r   r   r   
_has_alias?  s   zImportation._has_aliasc                 C   s&   |   rd| j d| j S d| j S )z5Generate a source statement equivalent to the import.import  as z	import %sr   r   r4   r   r   r   r   source_statementC  s   
zImportation.source_statementc                 C   s   |   r| jd | j S | jS z#Return import full name with alias.r   r   r   r   r   r   r   K  s   zImportation.__str__r   )rh   ri   rj   rk   r   r   r   propertyr   r   r   r   r   r   r   r   +  s    
r   c                       s@   e Zd ZdZ fddZ fddZdd Zedd	 Z  Z	S )
r   a  
    A binding created by a submodule import statement.

    A submodule import is a special case where the root module is implicitly
    imported, without an 'as' clause, and the submodule is also imported.
    Python does not restrict which attributes of the root module may be used.

    This class is only used when the submodule import is without an 'as' clause.

    pyflakes handles this case by registering the root module name in the scope,
    allowing any attribute of the root module to be accessed.

    RedefinedWhileUnused is suppressed in `redefines` unless the submodule
    name is also the same, to avoid false positives.
    c                    sB   d|v r|rt |tjsJ |dd }t || || _d S )Nr   r   )r   r   Importr   r   r   r   )rb   r4   r   package_namer   r   r   r   d  s   
zSubmoduleImportation.__init__c                    s"   t |tr| j|jkS t |S r   )r   r   r   r   r   r   r   r   r   r   k  s   
zSubmoduleImportation.redefinesc                 C   r   r   r   r   r   r   r   r   p  r   zSubmoduleImportation.__str__c                 C   s
   d| j  S )Nr   r   r   r   r   r   r   s     
z%SubmoduleImportation.source_statement)
rh   ri   rj   rk   r   r   r   r   r   r   r   r   r   r   r   S  s    r   c                       s2   e Zd Zd fdd	Zdd Zedd Z  ZS )	ImportationFromNc                    sH   || _ |p|| _|dr|| j }n|d | j }t ||| d S Nr   )module	real_nameendswithr   r   )rb   r4   r   r   r   r   r   r   r   r   z  s   

zImportationFrom.__init__c                 C   s"   | j | jkr| jd | j S | jS r   )r   r4   r   r   r   r   r   r     s   zImportationFrom.__str__c                 C   s<   | j | jkrd| j d| j  d| j S d| j d| j S )Nfrom z import r   )r   r4   r   r   r   r   r   r     s   z ImportationFrom.source_statementr   )rh   ri   rj   r   r   r   r   r   r   r   r   r   r   x  s
    r   c                       s4   e Zd ZdZ fddZedd Zdd Z  ZS )StarImportationz3A binding created by a 'from x import *' statement.c                    s"   t  d| |d | _|| _d S )N*z.*)r   r   r4   r   r   r   r   r   r     s   

zStarImportation.__init__c                 C   s   d| j  d S )Nr   z	 import *r   r   r   r   r   r     s   z StarImportation.source_statementc                 C   s   | j dr	| jS | jS r   )r   r   r   r4   r   r   r   r   r     s   zStarImportation.__str__)	rh   ri   rj   rk   r   r   r   r   r   r   r   r   r   r     s    
r   c                       r   )FutureImportationzs
    A binding created by a from `__future__` import statement.

    `__future__` imports are implicitly used.
    c                    s   t  ||d ||f| _d S )N
__future__)r   r   r   )rb   r4   r   scoper   r   r   r     s   zFutureImportation.__init__rh   ri   rj   rk   r   r   r   r   r   r   r     s    r   c                   @   r   )Argumentz3
    Represents binding a name as an argument.
    Nr   r   r   r   r   r     r   r   c                   @   r   )r   a  
    Represents binding a name with an explicit assignment.

    The checker will raise warnings for any Assignment that isn't used. Also,
    the checker does not consider assignments in tuple/list unpacking to be
    Assignments, rather it treats them as simple Bindings.
    Nr   r   r   r   r   r     r   r   c                   @   r   )NamedExprAssignmentzB
    Represents binding a name with an assignment expression.
    Nr   r   r   r   r   r     r   r   c                   @      e Zd ZdZdd ZdS )
Annotationa  
    Represents binding a name to a type without an associated value.

    As long as this name is not assigned a value in another binding, it is considered
    undefined for most purposes. One notable exception is using the name as a type
    annotation.
    c                 C      dS )zAAn Annotation doesn't define any name, so it cannot redefine one.Fr   r   r   r   r   r     s   zAnnotation.redefinesN)rh   ri   rj   rk   r   r   r   r   r   r     s    r   c                   @      e Zd ZdS )FunctionDefinitionNrh   ri   rj   r   r   r   r   r         r   c                   @   r   )ClassDefinitionNr   r   r   r   r   r     r   r   c                       r   )ExportBindinga  
    A binding created by an C{__all__} assignment.  If the names in the list
    can be determined statically, they will be treated as names for export and
    additional checking applied to them.

    The only recognized C{__all__} assignment via list/tuple concatenation is in the
    following format:

        __all__ = ['a'] + ['b'] + ['c']

    Names which are imported and not otherwise used but appear in the value of
    C{__all__} will not have an unused import warning reported for them.
    c                    s   d|v rt |tjrt|d j _ng  _ fdd}t |jtjtjfr,||j n@t |jtjrl|j}t |j	tjtjfrl|j
}|j	}|| t |tjrS|}nt |tjtjfra|| nn
t |j	tjtjfs@t || d S )N__all__c                    s6   | j D ]}t|tjrt|jtr j|j qd S r   )r,   r   r   r   r   strnamesappend)	containerr"   r   r   r   _add_to_names  s
   
z-ExportBinding.__init__.<locals>._add_to_names)r   r   	AugAssignrt   r   r   Listr*   BinOprightleftr   r   )rb   r4   r   r   r   currentValuer   r   r   r   r   r     s(   zExportBinding.__init__r   r   r   r   r   r     s    r   c                   @   r   )ScopeFc                 C   s,   | j j}d| dt| ddt|  dS )N<z at 0xx >)rq   rh   r1   dictr   )rb   	scope_clsr   r   r   r     s   $zScope.__repr__N)rh   ri   rj   importStarredr   r   r   r   r   r     s    r   c                   @   r   )
ClassScopeNr   r   r   r   r   r     r   r   c                       s<   e Zd ZdZdZh dZ fddZdd Zdd	 Z  Z	S )
FunctionScopezp
    I represent a name scope for a function.

    @ivar globals: Names declared 'global' in this function.
    F>   __tracebackhide____traceback_info____traceback_supplement__c                    s    t    | j | _d | _d S r   )r   r   
alwaysUsedcopyglobalsreturnValuer   r   r   r   r   )  s   

zFunctionScope.__init__c                 c   sJ    |   D ]\}}|js"|dkr"|| jvr"| js"t|tr"||fV  qdS )zR
        Return a generator for the assignments which have not been used.
        _N)rm   r   r   
usesLocalsr   r   rb   r4   bindingr   r   r   unused_assignments/  s   

z FunctionScope.unused_assignmentsc                 c   s2    |   D ]\}}|jst|tr||fV  qdS )zR
        Return a generator for the annotations which have not been used.
        N)rm   r   r   r   r   r   r   r   unused_annotations;  s   
z FunctionScope.unused_annotations)
rh   ri   rj   rk   r   r   r   r   r   r   r   r   r   r   r     s    r   c                   @   r   )	TypeScopeNr   r   r   r   r   r   D  r   r   c                   @   r   )GeneratorScopeNr   r   r   r   r   r   H  r   r   c                   @      e Zd ZdZdZdZdS )ModuleScopezScope for a module.TFN)rh   ri   rj   rk   _futures_allowed_annotations_future_enabledr   r   r   r   r   L      r   c                   @   r   )DoctestScopezScope for a doctest.Nr   r   r   r   r   r   R  r   r   c                   @   s   e Zd Ze ZdS )DetectClassScopedMagicN)rh   ri   rj   dirr   r   r   r   r   r   V  s    
r   )__file____builtins____annotations__WindowsErrorc                 C   s4   t | dr| jS t | dr| jS t | dr| jS d S )Nr1   r4   rest)hasattrr1   r4   r   r!   r   r   r   r   _  s   


r   )typingtyping_extensionsc                    s`    fdd}fdd}t | tjo|| jp/t | tjo/t | jtjo/|| jjo/ | jS )aX  
    Internal helper to determine whether or not something is a member of a
    typing module. This is used as part of working out whether we are within a
    type annotation context.

    Note: you probably don't want to use this function directly. Instead see the
    utils below which wrap it (`_is_typing` and `_is_any_typing_member`).
    c                    sH   t D ]}| |v r!t||  to||  jtv o ||  j  S qdS r   )reversedr   r   r   TYPING_MODULESr   r4   r   is_name_match_fnscope_stackr   r   _bare_name_is_attrv  s   z-_is_typing_helper.<locals>._bare_name_is_attrc                    s:   t  D ]}| |v rt||  to||  jtv   S qdS r   )r   r   r   r   r   r  r  r   r   _module_scope_is_typing  s   z2_is_typing_helper.<locals>._module_scope_is_typing)r   r   r0   r1   r2   r   r3   )r"   r  r  r  r  r   r  r   _is_typing_helperl  s   

r  c                    s   t |  fdd|S )z
    Determine whether `node` represents the member of a typing module specified
    by `typing_attr`.

    This is used as part of working out whether we are within a type annotation
    context.
    c                    s   |  kS r   r   r   typing_attrr   r   <lambda>  s    z_is_typing.<locals>.<lambda>r  )r"   r  r  r   r
  r   
_is_typing  s   r  c                 C   s   t | dd |S )z
    Determine whether `node` represents any member of a typing module.

    This is used as part of working out whether we are within a type annotation
    context.
    c                 S   r   NTr   r	  r   r   r   r    s    z'_is_any_typing_member.<locals>.<lambda>r  )r"   r  r   r   r   _is_any_typing_member  s   r  c                    s.   t | jtjtjfot fdd| jjD S )Nc                 3   s    | ]	}t |d  V  qdS )overloadN)r  )r   decr  r   r   r(     
    

z%is_typing_overload.<locals>.<genexpr>)r   r   r   FunctionDefAsyncFunctionDefanydecorator_list)r   r  r   r  r   is_typing_overload  s
   r  c                   @   r   )AnnotationStater   r<      N)rh   ri   rj   NONESTRINGBAREr   r   r   r   r    r   r  c                       t   fdd}|S )Nc                    sB   |     | g|R i |W  d    S 1 sw   Y  d S r   )_enter_annotationrb   argskwargsfuncr   r   in_annotation_func  s   
$z)in_annotation.<locals>.in_annotation_func	functoolswrapsr$  r%  r   r#  r   in_annotation     r*  c                    r  )Nc                    sF   |  tj  | g|R i |W  d    S 1 sw   Y  d S r   )r  r  r  r   r#  r   r   r%    s   $z0in_string_annotation.<locals>.in_annotation_funcr&  r)  r   r#  r   in_string_annotation  r+  r,  c                   @   sP  e Zd ZdZejeejeej	e
eje
eje
ejeejeejeejei	ZdZdZejZeeeZejdZ e rAe!e "d [ dddejv dfd	d
Z#dd Z$dd Z%dd Z&e'dd Z(e(j)dd Z(e'dd Z*e*j)dd Z*e'dd Z+e,j-dd Z.dd Z/dd Z0dd  Z1d!d" Z2d#d$ Z3d%d& Z4d'd( Z5d)d* Z6d+d, Z7d-d. Z8d/d0 Z9d1d2 Z:d3d4 Z;d5d6 Z<e,j-ej=fd7d8Z>e'd9d: Z?dd;d<Z@d=d> ZAd?d@ ZBdAdB ZCdCdD ZDeEF jGZHdEdF ZIeJdGdH ZKdIdJ ZLeMdKdL ZNdMdN ZOe@ ZP ZQ ZR ZS ZT ZU ZV ZWZXeOZYe@ ZZ Z[ Z\ Z] Z^ Z_Z`dOdP ZadQdR ZbdSdT ZcdUdV ZddWdX ZedYdZ Zfe@ Zg ZhZieO Zj Zk Zl Zm ZnZoeO Zp Zq Zr Zs Zt Zu Zv Zw Zx Zy Zz Z{ Z| Z} Z~ Z Z Z Z Z Z Z Z Z Z Z Z ZZd[d\ Ze@ Z ZZd]Zd^d_ Zd`da Zdbdc ZeZddde Zdfdg ZeZdhdi Ze Z ZZdjdk Zdldm ZeZdndo Zdpdq Ze ZZdrds ZeZdtdu Zdvdw Zdxdy Zdzd{ Zd|d} Zd~d ZeZdd Zdd Zdd ZeZdd Zdd Zdd Ze@ Z Z Z ZZe@ ZZdd Ze Z ZZe,j-dd Zdd Zdd ZdS )Checkerz2I check the cleanliness and sanity of Python code.r   NPYFLAKES_BUILTINS,z(none)PYFLAKES_DOCTESTr   c                 C   s   i | _ t | _g | _g | _|| _|r| j|| _|| _	dg| _
|| _g | _z	tjt| }W n ty=   td| w | | | jD ]
}| d t| qG| | |   W d    n1 sew   Y  |   |rytjddd d S d S )Nr   z$No scope implemented for the node %rz1`file_tokens` will be removed in a future versionr  )
stacklevel)_nodeHandlerscollectionsdeque	_deferred
deadScopesr   filenamebuiltInsunionwithDoctestexceptHandlersroot
scopeStackr-  _ast_node_scoper   KeyErrorRuntimeErrorin_scope
addBindingr   handleChildren_run_deferredcheckDeadScopeswarningswarn)rb   treer7  builtinsr:  file_tokensscope_tpbuiltinr   r   r   r     s:   




zChecker.__init__c                 C   s"   | j || jdd | jf dS )a{  
        Schedule a function handler to be called just before completion.

        This is used for handling function bodies, which must be deferred
        because code later in the file might modify the global scope. When
        `callable` is called, the scope at the time this is called will be
        restored, however it will contain any new bindings added to it.
        N)r5  r   r=  offset)rb   callabler   r   r   deferFunction  s   "	zChecker.deferFunctionc                 C   sL   | j | jf}| jr| j \}}}||| _ | _|  | js	|\| _ | _d S r   )r=  rM  r5  popleft)rb   orighandlerr   rM  r   r   r   rD    s   zChecker._run_deferredc                 C   s   t | jdkot| jd tS )Nr  r<   )r=   r=  r   r   r   r   r   r   _in_doctest  s   zChecker._in_doctestc                 C   s    t dd | jD sdS | jjS )Nc                 s   s    | ]}t |tV  qd S r   )r   r   )r   r   r   r   r   r(   "  s    z)Checker.futuresAllowed.<locals>.<genexpr>F)r+   r=  r   r   r   r   r   r   futuresAllowed   s
   zChecker.futuresAllowedc                 C   s(   |du sJ t | jtrd| j_d S d S r   )r   r   r   r   rb   r   r   r   r   rT  (  s   c                 C   s   | j d }t|tsdS |jS )Nr   F)r=  r   r   r   )rb   r   r   r   r   annotationsFutureEnabled.  s   

z Checker.annotationsFutureEnabledc                 C   s(   |du sJ t | jtsJ d| j_d S r  )r   r   r   r   rU  r   r   r   rV  5  s   c                 C   s
   | j d S )Nr   )r=  r   r   r   r   r   ;  r   zChecker.scopec              
   c   sD    | j |  zd V  W | j| j   d S | j| j   w r   )r=  r   r6  pop)rb   clsr   r   r   rA  ?  s
   *zChecker.in_scopec              	      s  | j D ] t trqt tr4  D ]\}}| tj|j| q 	 D ]\}}| tj
|j| q& d}|rBt|tsBd}|rTt|j} fdd|jD }ng  }}|r jsvtj| jdkrv|D ]}| tj d j| qh jrg }  D ]}t|tr||_||j qdt|}|D ]}| tj d j|| q  D ]@}t|tr|jp|j|v }|stj}	| |	|jt | |j!D ]}
t| "|
t#rtj$}	n|rqtj%}	| |	|
|j|j qqqdS )z
        Look at scopes which have been fully examined and report names in them
        which were imported but unused.
        r   Nc                    s   g | ]}| vr|qS r   r   )r   r4   r   r   r   r   ]  s
    z+Checker.checkDeadScopes.<locals>.<listcomp>__init__.py, )&r6  r   r   r   r   reportr   UnusedVariabler   r   UnusedAnnotationrl   r   setr   r   ospathbasenamer7  UndefinedExportvaluesr   r   r   r   joinra   ImportStarUsager   r4   UnusedImportr   r   	getParent	FOR_TYPESImportShadowedByLoopVarRedefinedWhileUnused)rb   r4   r   all_binding	all_names	undefined	from_listr   r   messgr"   r   rY  r   rE  G  sh   









zChecker.checkDeadScopesc                 O   s$   | j || jg|R i | d S r   )r   r   r7  )rb   messageClassr!  r"  r   r   r   r\    s   $zChecker.reportc                 C   s"   	 |j }t|dst|ds|S q)NTr,   ctx)_pyflakes_parentr   rb   r"   r   r   r   rh    s
   zChecker.getParentc                 C   sz   |||fv st |drt |dsd S ||u r|S |j|jkr&| |j||S |j|jk r4| ||j|S | |j|j|S Nrs  )r   _pyflakes_depthgetCommonAncestorrs  )rb   lnodernodestopr   r   r   rw    s"   zChecker.getCommonAncestorc                 C   s"   |D ]}|  |||r dS qdS )NTF)rw  )rb   r"   	ancestorsrz  ar   r   r   descendantOf  s
   zChecker.descendantOfc                 C   s.   |}	 || j u r
d S | |}t||r|S qr   )r<  rh  r   )rb   r"   ancestor_typeparentr   r   r   _getAncestor  s   


zChecker._getAncestorc                 C   s   |  |ttj S r   )r  rY   r-  r>  keysrt  r   r   r   getScopeNode  r   zChecker.getScopeNodec                 C   sL   |  ||| j}t|}|r$|D ]}| |||| |||A r# dS qdS )zATrue, if lnode and rnode are located on different forks of IF/TRYTF)rw  r<  r   r}  )rb   rx  ry  ancestorpartsrm   r   r   r   differentForks  s   zChecker.differentForksc                 C   s  | j ddd D ]	}|j|v r nq||j}|r{t|ts{| ||js{| |j}t|trBt|t	rB| 
tj||j|j n9|| ju rk|jsj||rj|jdksYt|trjt|| j sj| 
tj||j|j nt|tr{||r{|j| |j| jv r| j|j j|_|j| jvst|tsd}t|trt| j | tr|d8 }t|trt| j | ts|| j | |j< dS dS )z
        Called when a binding is altered.

        - `node` is the statement responsible for the change
        - `value` is the new value, a Binding instance
        Nr   r   r<   )r=  r4   rl   r   r   r  r   rh  r   ri  r\  r   rj  r   r   r   r  rk  r   r   r   r   r   )rb   r"   r   r   existingparent_stmtcur_scope_posr   r   r   rB    sT   




zChecker.addBindingc                 C   s,   t jdrtdt| | | d S )NPYFLAKES_ERROR_UNKNOWNzUnexpected type: )r`  environrl   NotImplementedErrorr   rC  rt  r   r   r   _unknown_handler  s   zChecker._unknown_handlerc                 C   sF   z| j | W S  ty   |j }Y nw t| || j | j |< }|S r   )r2  r?  rh   upperrr   r  )rb   rc   nodeTyperR  r   r   r   getNodeHandler  s   zChecker.getNodeHandlerc           
   	   C   s2  t |}|sd S d }d }| jdd d D ]}t|tr'|dkr" d S |du r'q||d }t|tr>| js>| j|f|| _q|dkr[t|t	r[t|t
jr[t|jt
jr[| tj| z8| j|f|| _|| }t|tr| rz| j|f||j _W W  d S  ty   Y W  d S w W  d S W  d S  ty   Y nw |p|j}|durt|ttf}q|rg }	| jdd d D ]}| D ]}t|tr| j|f|_|	|j qqdt|	}	| tj|||	 d S |dkrtj | j!dkrd S |t"j#v rt| jtrd S d| j$d vr| tj%|| d S d S )	Nr   rq   Fprintr[  __path__rZ  	NameError)&r   r=  r   r   rl   r   _in_postponed_annotationr   r   r   r   r   opRShiftr\  r   InvalidPrintSyntaxr   r   r   r?  r   r   r   rd  r   r   re  ra   rf  r`  ra  rb  r7  r   r   r;  UndefinedName)
rb   r"   r  r4   can_access_class_varsr   r   r   r   ro  r   r   r   handleNodeLoad  s~   


zChecker.handleNodeLoadc                 C   sl  t |}|sd S t| jtrP|| jvrP| jd d D ]5}t|ttfs$q||v o,|| j}|rO|d | ju rO|| jjvrO| t	j
|| jd ||| j  nq| |}t|tjrf|jd u rft||}nHt|ttjfsx||jkr~| |s~t||}n0|dkrt| jtrt|jtjtjtjfrt||j| j}nt|tjrt||}nt||}| || d S )Nr   r   r<   r   )r   r   r   r   r=  r   r   r   r\  r   UndefinedLocalr   rh  r   	AnnAssignr   r   ri  comprehensionrs  isLiteralTupleUnpackingr   Assignr   r   	NamedExprr   r   rB  )rb   r"   r4   r   r   r  r   r   r   r   handleNodeStoree  sF   



zChecker.handleNodeStorec                    s    fdd}t  }|sd S | rd S t| jtr(|| jjv r(| jj| d S z| j|= W d S  tyA   | tj	 | Y d S w )Nc                     s>   t  dd} | rt| tjtjtjfrdS t | dd} | sdS )zN
            Return `True` if node is part of a conditional body.
            rs  NTF)rr   r   r   r   WhileIfExp)currentr!   r   r   on_conditional_branch  s   z7Checker.handleNodeDelete.<locals>.on_conditional_branch)
r   r   r   r   r   remover?  r\  r   r  )rb   r"   r  r4   r   r!   r   handleNodeDelete  s   zChecker.handleNodeDeletec                 c   s,    | j |}| _ z	d V  W || _ d S || _ w r   )_in_annotation)rb   ann_typerQ  r   r   r   r    s
   zChecker._enter_annotationc                 C   s   | j tjkp| jS r   )r  r  r  rV  r   r   r   r   r    s   z Checker._in_postponed_annotationc                 C   s"   t ||dD ]}| || qd S )Nru   )rx   
handleNode)rb   rH  ru   r"   r   r   r   rC    s   zChecker.handleChildrenc                 C   s8   t |tjr|j|jg D ]
}t|ds dS qdS d S )Nr,   FT)r   r   r  targetsr   r   )rb   r"   childr   r   r   r    s   
zChecker.isLiteralTupleUnpackingc                 C   s(   t |tjot |jtjot |jjtS )z}
        Determine if the given node is a docstring, as long as it is at the
        correct place in the node tree.
        )r   r   Exprr   r   r   rt  r   r   r   isDocstring  s
   zChecker.isDocstringc                 C   s>   t |tjrt |jtjrt |jjtr|jj|jd fS dS )Nr<   )NN)r   r   r  r   r   r   r   rt  r   r   r   getDocstring  s   
zChecker.getDocstringc              	   C   s   |d u rd S | j r%t|dd d ur%| j| j d 7  _| j| j d 7  _| jr;| jdkr;t|tjs;| 	|s;d| _|  jd7  _| j|_
||_z| |j}|| W |  jd8  _d S |  jd8  _w )Nr   r   r<   F)rM  rr   r   
col_offsetrT  	nodeDepthr   r   
ImportFromr  rv  rs  r  rq   )rb   r"   r  rR  r   r   r   r    s(   


"zChecker.handleNodec                 C   sd  z|  |jd \}}|o| |}W n ttfy   Y d S w |s$d S | j}| jd g| _| jp2d}| tm d| jd vrH| 	d t
d |D ]S}z	t|jd}W n, ty }	 z ||j |	j |jd |	jpld f}
| tj||
 W Y d }	~	qJd }	~	ww |d | |j |d |j d f| _| | || _qJW d    n1 sw   Y  || _d S )Nr   )r   r   r   z	<doctest>   r<   )r  r   _getDoctestExamplesr?   rG   r=  rM  rA  r   rB  r   r   parser   SyntaxErrorr   indentr\  r   DoctestSyntaxErrorrC  )rb   r"   	docstringnode_linenoexamplessaved_stacknode_offsetexamplerH  epositionr   r   r   handleDoctests  s@   


zChecker.handleDoctestsc           
      C   s   zt |}W n ty   | ||| Y d S w |j}t|dks*t|d t js3| ||| d S |jd j}t 	|D ]}	d|	j
v rPd|	j
v rP||	_||	_q>| || d S )Nr<   r   r   r  )r   r  r  r\  r   r=   r   r  r   walk_attributesr   r  r  )
rb   rW   r"   
ref_linenoref_col_offseterrrH  r   parsed_annotation
descendantr   r   r   handleStringAnnotation  s$   

zChecker.handleStringAnnotationc                    s&   t tj fdd d S )Nc                      s    S r   r   r   
annotationfnr  rb   r   r   r  .  s    z;Checker.handle_annotation_always_deferred.<locals>.<lambda>)r*  r-  r  rO  )rb   r  r  r   r  r   !handle_annotation_always_deferred,  s   
z)Checker.handle_annotation_always_deferredc              
   C   sf   t |tjr t |jtr | t| j|j||j	|j
tj d S | jr+| || d S | || d S r   )r   r   r   r   r   rO  r'  partialr  r   r  r   ForwardAnnotationSyntaxErrorrV  r  r  )rb   r  r"   r   r   r   handleAnnotation0  s   


zChecker.handleAnnotationc                 C   s   d S r   r   rt  r   r   r   ignoreD  s   zChecker.ignorec                 C   s  t |jdr$| tj | | W d    d S 1 sw   Y  d S t |jdr| |j| t|jt	j
r<|j}nt|jt	jrPt|jjt	j
rP|jj}nd }|d u s]t|jdk re| |j| n/| |jd | | tj |jdd  D ]}| || q|W d    n1 sw   Y  | |j| d S t|j| jr|   | | W d    d S 1 sw   Y  d S | | d S )NLiteral	Annotatedr  r   r<   )r5   r   r  r  r  rC  r  r   slicer   r*   Indexr=   r,   rr  r  r=  )rb   r"   slice_tupleargr   r   r   	SUBSCRIPTQ  s8   "

"zChecker.SUBSCRIPTc                    s  zt tjjj}W n ty& } ztj| W Y d }~d S d }~ww d  dt t  fdd}|D ][\}}}}||rK d S |d urzt t|}W n tys } ztj| W Y d }~ d S d }~ww |D ]"\}}	}
}|
d urd|
v rtjd   d S ||	r  d S qvq>t	dd j
D st	dd jD rd S tttj
}d	d
 jD }| }| }B ||B  }|rtjdtdd |D  |rtjdt| |rtjdtdd |D  d S d S )Nr   c                    s   | du rdS |  d\} }}|  d\} }}zt| } W n	 ty%   Y nw  du r3tj dS d | dkrN du rFtj dS d } d7 t| trZ|  dS |  dS )z9Returns True if there is an error which should early-exitNFr   [T r<   )	partitionintr?   r\  r   StringDotFormatMixingAutomaticr   add)fmtkeyr   auto	next_autor"   placeholder_namedplaceholder_positionalrb   r   r   _add_key  s2   


z3Checker._handle_string_dot_format.<locals>._add_key{zMax string recursion exceededc                 s       | ]	}t |tjV  qd S r   r   r   Starredr   r  r   r   r   r(         z4Checker._handle_string_dot_format.<locals>.<genexpr>c                 s   s    | ]}|j d u V  qd S r   r  r   kwdr   r   r   r(     s    c                 S      h | ]}|j qS r   r  r  r   r   r   	<setcomp>  r	   z4Checker._handle_string_dot_format.<locals>.<setcomp>r[  c                 s   r$   r   r   r   r   r   r   r   r(     r)   c                 s   r$   r   r  r  r   r   r   r(     r)   )rY   parse_format_stringr$  r   r?   r\  r   StringDotFormatInvalidFormatr_  r  r!  keywordsranger=   'StringDotFormatExtraPositionalArgumentsre  ra   "StringDotFormatExtraNamedArgumentsStringDotFormatMissingArgument)rb   r"   placeholdersr  r  r   r  specspec_placeholdersspec_fmtkey	spec_specsubstitution_positionalsubstitution_namedextra_positionalextra_namedmissing_argumentsr   r  r   _handle_string_dot_formatw  s   'z!Checker._handle_string_dot_formatc                 C   sZ  t |jtjr"t |jjtjr"t |jjjtr"|jjdkr"| | g }g }g }t	|jd| j
rUt|jdkrU|   | |jd | W d    n1 sOw   Y  nt	|jd| j
r|dg7 }|dd |jdd  D 7 }|d	g7 }|d
d |jD 7 }|dd |jD 7 }nt	|jd| j
rt|jdkrt |jd tjr|dg7 }||jd j7 }|dd t|jD 7 }|d	g7 }|dd |jD 7 }|dd |jD 7 }n}t	|jd| j
rRt|jdkr9t |jd tjtjfr9tdd |jd jD r9|dg7 }|dd |jd jD 7 }|dd |jd jD 7 }|dd t|jD 7 }|dd |jd jD 7 }|d	g7 }|dd |jD 7 }|dd |jD 7 }|r| tj |D ]\}}| j||d q^| j||d W d    n	1 s}w   Y  |   |D ]	}| || qW d    d S 1 sw   Y  d S | | d S )Nr   castr<   r   TypeVarr!  c                 S   s   g | ]}|qS r   r   r  r   r   r   r     s    z Checker.CALL.<locals>.<listcomp>r  c                 S   s   g | ]
}|j d kr|jqS )bound)r  r   r   kr   r   r   r         c                 S   s$   g | ]}||j d krdgndfqS )r  r   Nr  r  r   r   r   r     s    	TypedDictc                 S   &   g | ]\}}||d krdgndfqS )r<   rd  Nr   r   rK   r  r   r   r   r         c                 S   r   r   r   r  r   r   r   r     r	   c                 S      g | ]}|d gfqS r  r   r  r   r   r   r         
NamedTuplec                 s   s0    | ]}t |tjtjfot|jd kV  qdS )r  N)r   r   r*   r   r=   r,   r  r   r   r   r(      s    
zChecker.CALL.<locals>.<genexpr>c                 S   s   g | ]}|j d  qS r<   r,   r&   r   r   r   r   $  r  c                 S   s   g | ]	}|j d  dfqS )r   Nr  r&   r   r   r   r   %  s    c                 S   r  )r<   r,   Nr   r  r   r   r   r   &  r  c                 S   s   g | ]}|d fqS r  r   r&   r   r   r   r   *  s    c                 S   r   r   r  r  r   r   r   r   .  r	   c                 S   r  r  r   r  r   r   r   r   /  r  r  )r   r$  r   r2   r   r   r   r3   r  r  r=  r=   r!  r  r  r  Dictrd  	enumerater*   r   r+   r,   r  r  rC  )rb   r"   ru   	annotatednot_annotatedna_nodena_omitannotated_noder   r   r   CALL  s   




 





$zChecker.CALLc                 C   sb  zt |jj}W n ty   | tj|d Y d S w t }d}d }|D ]t\}}|d u r-q$|\}}}	}
}|dkr9q$|tvrE| tj	|| |d u rO|rO|d u }|	|
fD ]}|d urkd|v rk|sg| tj
| qS|d7 }qS|r||d ur|| tj|  d S |s|d u r| tj|  d S |r|d7 }q$|| q$t|jtjtjfrtdd |jjD st|jj}|r||kr| tj||| n	|s| tj| t|jtjr)tdd |jjD r+|r|dkr| tj| d S d	d
 |jjD }|| }|| }|s|r| tj|dt| |s-|r/| tj|dt| d S d S d S d S d S )Nzincomplete formatr   r;   r   r<   c                 s   r  r   r  r&   r   r   r   r(   |  r  z1Checker._handle_percent_format.<locals>.<genexpr>c                 s   s(    | ]}t |tjot |jtV  qd S r   )r   r   r   r   r   r  r   r   r   r(     s
    
c                 S   r  r   r  r  r   r   r   r    r	   z1Checker._handle_percent_format.<locals>.<setcomp>r[  )rZ   r   r   r?   r\  r   PercentFormatInvalidFormatr_  VALID_CONVERSIONS'PercentFormatUnsupportedFormatCharacter!PercentFormatStarRequiresSequence$PercentFormatMixedPositionalAndNamedr  r   r   r   r   r*   r  r,   r=   $PercentFormatPositionalCountMismatchPercentFormatExpectedMappingr  r+   r  PercentFormatExpectedSequence PercentFormatExtraNamedArgumentsre  ra   PercentFormatMissingArgument)rb   r"   r  namedpositional_count
positionalr   placeholderr4   rQ   rS   rT   partsubstitution_countsubstitution_keys
extra_keysmissing_keysr   r   r   _handle_percent_format=  s   
zChecker._handle_percent_formatc                 C   sB   t |jtjrt |jtjrt |jjtr| | | 	| d S r   )
r   r  r   Modr   r   r   r   r0  rC  rt  r   r   r   BINOP  s   
zChecker.BINOPc                 C   sF   t |jtr| jr!t| j|j||j|jt	j
}| | d S d S d S r   )r   r   r   r  r'  r  r  r   r  r   r  rO  )rb   r"   r  r   r   r   CONSTANT  s   zChecker.CONSTANTc                 C   sZ   |  | |j}t|tjrt|jr| tj	| d S d S t|r+| tj	| d S d S r   )
rC  excr   r   Callr   r$  r\  r   RaiseNotImplemented)rb   r"   r  r   r   r   RAISE  s   

zChecker.RAISEFc                 C   sV   | j stdd |jD s| tj| d| j | _ }z| | W || _ d S || _ w )Nc                 s   r  r   )r   r   FormattedValuer  r   r   r   r(     r  z$Checker.JOINEDSTR.<locals>.<genexpr>T)_in_fstringr  rd  r\  r   FStringMissingPlaceholdersrC  )rb   r"   rQ  r   r   r   	JOINEDSTR  s   zChecker.JOINEDSTRc           	         s   dd j D }t|}dd | D }|D ]D  fddt|D }tfdd|D }tdd | D r[|D ]}j | }t trR| tj	| j
 q<| tj|  q<q|  d S )Nc                 S   s   g | ]}t |qS r   ry   )r   rM   r   r   r   r     s    z Checker.DICT.<locals>.<listcomp>c                 S   s   g | ]
\}}|d kr|qS r  r   )r   rM   countr   r   r   r     s
    c                    s   g | ]
\}}| kr|qS r   r   )r   rK   i_key)rM   r   r   r     r
  c                 3   s    | ]
}t  j| V  qd S r   )rz   rd  )r   r>   r!   r   r   r(     s
    
zChecker.DICT.<locals>.<genexpr>c                 s   s    | ]	\}}|d kV  qdS )r<   Nr   )r   r   r<  r   r   r   r(     r  )r  rp   rm   r  r  r   r|   r\  r   MultiValueRepeatedKeyVariabler4   MultiValueRepeatedKeyLiteralrC  )	rb   r"   r  
key_countsduplicate_keyskey_indicesrd  	key_indexkey_noder   )rM   r"   r   DICT  s6   

zChecker.DICTc                 C   6   t |jtjr|jjg kr| tj| | | d S r   )	r   testr   r*   r,   r\  r   IfTuplerC  rt  r   r   r   IF     z
Checker.IFc                 C   rF  r   )	r   rG  r   r*   r,   r\  r   AssertTuplerC  rt  r   r   r   ASSERT  rJ  zChecker.ASSERTc                    s   |   rdnd}| j| }| j|urC|jD ]/ t |} fdd| jD | _| | ||f|_| j|d d D ]}|| < q;qdS dS )z5
        Keep track of globals declarations.
        r<   r   c                    s*   g | ]}t |tjr|jd   kr|qS )r   )r   r   r  message_args)r   m	node_namer   r   r   *  s    
z"Checker.GLOBAL.<locals>.<listcomp>N)rS  r=  r   r   r   r   
setdefaultr   )rb   r"   global_scope_indexglobal_scope
node_valuer   r   rO  r   GLOBAL  s   






zChecker.GLOBALc                 C   s:   |  t | | W d    d S 1 sw   Y  d S r   )rA  r   rC  rt  r   r   r   GENERATOREXP9  s   "zChecker.GENERATOREXPc                 C   s   t |jtjr.| || | |jdkr(t | jtr*t |j	tj
r,d| j_dS dS dS dS t |jtjr<| | dS t |jtjrJ| | dS td|j)zV
        Handle occurrence of Name (which can be a load/store/delete access.)
        localsTz#Got impossible expression context: N)r   rr  r   Loadr  rh  r1   r   r   rs  r5  r   Storer  Delr  r@  rt  r   r   r   NAME?  s   zChecker.NAMEc                 C   s   |}t |dr.|j|}}t|tjtjtjfr||jvrd S t|tjtj	fr)nt |dst|tj
r=| tj| d S | tj| d S ru  )r   rs  r   r   r  ForAsyncForr   r  ClassDefContinuer\  r   ContinueOutsideLoopBreakOutsideLoop)rb   r"   r   n_childr   r   r   CONTINUER  s   


zChecker.CONTINUEc                 C   sX   t | jttfr| tj| d S |jr#t| jdr#| jj	s#|j| j_	| 
|j| d S )Nr   )r   r   r   r   r\  r   ReturnOutsideFunctionr   r   r   r  rt  r   r   r   RETURNf  s   

zChecker.RETURNc                 C   s4   t | jttfr| tj| d S | |j| d S r   )	r   r   r   r   r\  r   YieldOutsideFunctionr  r   rt  r   r   r   YIELDs  s   zChecker.YIELDc                    s    j D ]}|  q    W d    n1 s!w   Y   t j  jrI sKt	j
tsM fdd d S d S d S d S )Nc                      
     S r   r  r   r"   rb   r   r   r       
 z%Checker.FUNCTIONDEF.<locals>.<lambda>)r  r  _type_param_scopeLAMBDArB  r   r4   r:  rS  r   r   r   rO  )rb   r"   decor   rj  r   FUNCTIONDEF|  s   

zChecker.FUNCTIONDEFc                    sP  g }g } j jD ]}||j ||j q j j  j j D ]}||j ||j q j j j j }t t	j
 }dD ]}t j |}|sJq?||j |rX||j q?|ra| j tt|t|k rt|D ]\}	}||d |	 v rtj | qo|D ]}
|
  q|D ]}|  q fdd}| d S )N)varargkwargc                      s>    t j dd W d    d S 1 sw   Y  d S )N)r  returnstype_paramsr  )rA  r   rC  r   rj  r   r   runFunction  s   "z#Checker.LAMBDA.<locals>.runFunction)r!  posonlyargsr   r  r  
kwonlyargsdefaultskw_defaultsr   r   Lambdarr   rr  r=   r_  r  r\  r   DuplicateArgumentr  r  rO  )rb   r"   r!  annotationsr  rw  has_annotationsarg_namewildcardidxr  defaultrt  r   rj  r   rm    s>   zChecker.LAMBDAc                 C   s   | j |dd d S )N)rw  rx  r  )rC  rt  r   r   r   	ARGUMENTS  r/   zChecker.ARGUMENTSc                 C   s   |  |t|j| | d S r   )rB  r   r  r  rt  r   r   r   ARG  s   zChecker.ARGc              	      s    j D ]}|  q X  jD ]}|  q jD ]}|  q!t+ jrG sGt	j
tsG fdd  jD ]}|  qJW d   n1 s]w   Y  W d   n1 slw   Y   t j  dS )z
        Check names used in a class definition, including its decorators, base
        classes, and the body of its definition.  Additionally, add its name to
        the current scope.
        c                      rh  r   ri  r   rj  r   r   r    rk  z"Checker.CLASSDEF.<locals>.<lambda>N)r  r  rl  basesr  rA  r   r:  rS  r   r   r   rO  r   rB  r   r4   )rb   r"   rn  baseNodekeywordNodestmtr   rj  r   CLASSDEF  s*   




zChecker.CLASSDEFc                 C   s.   |  |j| | |j| | |j| d S r   )r  targetr  r   rt  r   r   r   	AUGASSIGN  s   zChecker.AUGASSIGNc                 C   s   t |jtjr@d}d}t|jD ]\}}t |tjr)|r%| tj	|  nd}|}q|dks9t
|j| d dkr@| tj| | | d S )NFr   T   r<   i   )r   rr  r   rY  r  r,   r  r\  r   TwoStarredExpressionsr=   %TooManyExpressionsInStarredAssignmentrC  )rb   r"   has_starredstar_locrK   r   r   r   r   TUPLE  s   zChecker.TUPLEc                 C   sT   |j D ]$}d|jv r|jst|j|}n|jp|j}t|||j}| || qd S r   )r   r4   asnamer   r   rB  )rb   r"   aliasimportationr4   r   r   r   IMPORT  s   
zChecker.IMPORTc                 C   s  |j dkr| js| tj| nd| _d|j |j pd }|jD ]`}|jp'|j}|j dkrLt	||| j
}|jtjvrC| tj||j |jdkrKd| _n.|jdkrrt| j
ts`| tj|| q d| j
_| tj|| t||}nt||||j}| || q d S )Nr   Fr   r  r{  Tr   )r   rT  r\  r   LateFutureImportlevelr   r  r4   r   r   r   all_feature_namesFutureFeatureNotDefinedrV  r   r   ImportStarNotPermittedr   ImportStarUsedr   r   rB  )rb   r"   r   r  r4   r  r   r   r   
IMPORTFROM  s>   




zChecker.IMPORTFROMc                 C   s   g }t |jD ]:\}}t|jtjr!|jjD ]	}|t| qn|jr,|t|j |jd u rA|t	|jd k rA| 
tj| q| j| |jD ]}| || qK| j  | j|dd d S )Nr<   r   r  )r  r   r   r   r   r*   r,   r   r   r=   r\  r   DefaultExceptNotLastr;  r   r  rW  rC  )rb   r"   handler_namesrK   rR  exc_typer  r   r   r   TRY!  s    

zChecker.TRYc                 C   s   |j d u r| | d S |j | jv r| | z	| j|j }W n ty+   d }Y nw | | | | z	| j|j }W n	 tyH   Y nw |jsU| tj	||j  |r_|| j|j < d S d S r   )
r4   rC  r   r  rW  r?  r   r\  r   r]  )rb   r"   prev_definitionr   r   r   r   EXCEPTHANDLER7  s,   




zChecker.EXCEPTHANDLERc                 C   sT   |  |j| |jr!t|jd| jr|  |j| n| |j| | |j| d S )N	TypeAlias)r  r  r   r  r=  r  r  rt  r   r   r   	ANNASSIGNd  s   zChecker.ANNASSIGNc                 C   s`   |j }t|j|jD ]\}}t|tjtjfr&t|st|r&| 	t
j| |}q
| | d S r   )r   zipopscomparatorsr   r   IsIsNotr.   r\  r   	IsLiteralrC  )rb   r"   r   r  r   r   r   r   COMPAREo  s   zChecker.COMPAREc                 C   s   |  | | | d S r   )r  rC  rt  r   r   r   _match_target  s   
zChecker._match_targetc                 c   sh    t  %}tjdkr|| t |jD ]}| || qd V  W d    d S 1 s-w   Y  d S )N)r
      )	
contextlib	ExitStackr   r   enter_contextrA  r   rs  r  )rb   r"   rr  paramr   r   r   rl    s   


"zChecker._type_param_scopec                 C   s   |  | | |j| d S r   )r  r  r  rt  r   r   r   TYPEVAR  s   
zChecker.TYPEVARc                 C   sL   |  |j| | | | |j| W d    d S 1 sw   Y  d S r   )r  r4   rl  r  r   rt  r   r   r   	TYPEALIAS  s   "zChecker.TYPEALIASr   )rh   ri   rj   rk   r   Moduler   r^  r   r  r   r  ry  ListCompr   SetCompGeneratorExpDictCompr>  r  rM  r  r  r  r_  builtin_varsr9  _MAGIC_GLOBALSr8  r`  r  rl   _customBuiltInsupdater   r   rO  rD  rS  r   rT  setterrV  r   r  contextmanagerrA  rE  r\  rh  rw  r}  r  r  r  rB  r  r  r  r  r  r  r  r  rC  r  r  r  r  doctestDocTestParserget_examplesr  r  r,  r  r  r*  r  r  DELETEFORASYNCFORWHILEWITHWITHITEM	ASYNCWITHEXPRASSIGNPASSBOOLOPUNARYOPSET	ATTRIBUTESTARREDNAMECONSTANT	NAMEDEXPRr  r  r  r0  r2  r3  SLICEEXTSLICEINDEXLOADSTOREDELAUGLOADAUGSTOREPARAMANDORADDSUBMULTDIVMODPOWLSHIFTRSHIFTBITORBITXORBITANDFLOORDIVINVERTNOTUADDUSUBEQNOTEQLTLTEGTGTEISISNOTINNOTINMATMULTr7  COMPREHENSIONKEYWORDFORMATTEDVALUEr9  r;  rE  rI  IFEXPrL  rU  NONLOCALrV  LISTCOMPDICTCOMPSETCOMPr[  rc  BREAKre  rg  AWAIT	YIELDFROMro  ASYNCFUNCTIONDEFrm  r  r  r  r  r  LISTr  r  r  TRYSTARr  r  r  MATCH
MATCH_CASE
MATCHCLASSMATCHORMATCHSEQUENCEMATCHSINGLETON
MATCHVALUEr  MATCHASMATCHMAPPING	MATCHSTARrl  r  r  r   r   r   r   r-    sH   

!






B	1
T*



 

&sSj	*$-	 -
r-  )Srk   r   rI  r   r3  r  r  r'  r`  rer8   r   rF  pyflakesr   r   PYPYr   r  	Formatterr  r  r   r\  r]  ri  r#   r-   r%   r.   r5   compiler@   rC   rD   rE   rF   	frozensetr  r:   rZ   r   r[   rp   rx   rz   r   r   r   r   r}   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r  r  r  r  r  r*  r,  r-  r   r   r   r   <module>   s    

	




@ (%
1%
,

