B
    0zf                 @   s  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 d dlm	Z	 d dl
mZmZ d dlmZ d dlZd dlZdZedZe je je je je je je je je jf	Ze je je jfZedd	d
gZej ddG dd dZ!dd Z"dd Z#dd Z$dd Z%dd Z&ej G dd de j'Z(dd Z)ej G dd de j'Z*G dd  d e j'Z+G d!d" d"e*Z,ed#d$Z-eee-e!d%d&Z.e.d'd(Z/e.d)d(Z0e.d*d(Z1e.d+d(Z2e.d,d(Z3d-d.d/he3_4i e3_5e.d0d(Z6d1e6_7d2e6_8d3d4d5d6d7d8d9d:d;d<d=he6_9e.d>d(Z:e.d?d(Z;d@dAdBdCdDdEdFdGdHdIdJhe;_<e.dKd(Z=e.dLd(Z>e.dMd(Z?e.dNd(Z@e.dOd(ZAe.dPd(ZBdQdRdSdTdUdVhdWhdXeB_Ce.dYd(ZDe.dZd(ZEe.d[d(ZFe.d\d(ZGe.d]d(ZHd^d_d`daheH_Ie.dbd(ZJe.dcd(ZKe.ddd(ZLe.ded(ZMe.dfd(ZNe.dgd(ZOe.dhd(ZPe.did(ZQe.djd(ZRe.dkd(ZSdldmdnheS_TdogeS_UdpdqgeS_VdrdsdtdugeS_We.dvd(ZXe.dwd(ZYe.dxd(ZZe.dyd(Z[dzd{d|d}d~dgZ\dS )    N)
namedtuple)suppress)	lru_cachepartial)	iskeywordz22.12.6zflake8.bugbearContextnodestackF)hashc               @   s   e Zd ZdZeZejddZejddZ	ejddZ
ejddZejdedd d	ZejddZd
d Zdd Zedd Zdd Zedd Ze dd ZdS )BugBearCheckerzflake8-bugbearN)defaultz(none)O   Fc               C   s   t S )N)BugBearVisitor r   r   J/home/ankuromar296_gmail_com/.local/lib/python3.7/site-packages/bugbear.py<lambda>+       zBugBearChecker.<lambda>)initr   c             c   s   | j r| js|   | jr4t| jdr4t| jj}nt }| j| j| j|d}|	| j  x:t
|j|  D ]$}| |jd d rn| |V  qnW d S )Nextend_immutable_calls)filenamelinesb008_extend_immutable_calls   )treer   	load_fileoptionshasattrsetr   visitorr   visit	itertoolschainerrorsgen_line_based_checksshould_warnmessageadapt_error)selfr   r   er   r   r   run.   s    zBugBearChecker.runc       
      c   s   xt | jddD ]\}}|dkr,|dr,qt|d }|d| j kr| r| }t|dkol|d dk}t|dk}t|t|d  }|| jd	 k}|p|}	|	r|sqt|||| jfd
V  qW dS )zgen_line_based_checks() -> (error, error, error, ...)

        The following simple checks are based on the raw lines, not the AST.
           )startz#!g?   r   #   )varsN)	enumerater   
startswithlenmax_line_lengthstripsplitB950)
r'   linenolinelengthchunksZis_line_comment_url_pathZjust_long_url_pathZnum_leading_whitespacesZtoo_many_leading_white_spacesskipr   r   r   r#   A   s    z$BugBearChecker.gen_line_based_checksc             C   s   |j |jj|j ddd S )zBAdapts the extended error namedtuple to be compatible with Flake8.)r%   Nr   )_replacer%   formatr0   )clsr(   r   r   r   r&   b   s    zBugBearChecker.adapt_errorc             C   sN   | j dkr"d| _ t d| _nt| j | _| jsJtd	| j| _dS )zLoads the file in a way that auto-detects source encoding and deals
        with broken terminal encodings for stdin.

        Stolen from flake8_import_order because it's good.
        )stdin-Nr@   T N)
r   pycodestyleZstdin_get_value
splitlinesr   	readlinesr   astparsejoin)r'   r   r   r   r   g   s    
zBugBearChecker.load_filec             C   s"   |  t | jdddg dd dS )z)Informs flake8 to ignore B9xx by default.z--extend-immutable-callsTz.Skip B008 test for additional immutable calls.)comma_separated_listZparse_from_configr   helpN)Zextend_default_ignoredisabled_by_default
add_option)Z
optmanagerr   r   r   add_optionsw   s    
zBugBearChecker.add_optionsc             C   s   |dd dkrdS | j dkr.td| dS xftdt|d D ]P}| j jrf|d| | j jkrfdS t| j drB| j jrB|d| | j jkrBdS qBW td|| j j d	S )
a  Returns `True` if Bugbear should emit a particular warning.

        flake8 overrides default ignores when the user specifies
        `ignore = ` in configuration.  This is problematic because it means
        specifying anything in `ignore = ` implicitly enables all optional
        warnings.  This function is a workaround for this behavior.

        As documented in the README, the user is expected to explicitly select
        the warnings.

        NOTE: This method is deprecated and will be removed in a future release. It is
        recommended to use `extend-ignore` and `extend-select` in your flake8
        configuration to avoid implicitly altering selected and ignored codes.
        Nr,   ZB9Tz>Options not provided to Bugbear, optional warning %s selected.r*   extend_selectzOOptional warning %s not present in selected warnings: %r. Not firing it at all.F)r   LOGinforanger3   selectr   rN   )r'   codeir   r   r   r$      s$    

zBugBearChecker.should_warn)__name__
__module____qualname__name__version__versionattribr   r   r   r4   Factoryr   r   r)   r#   classmethodr&   r   staticmethodrM   r   r$   r   r   r   r   r   "   s   !r   c             C   s"   t | tjsdS td| jd k	S )NFz^[A-Za-z_][A-Za-z0-9_]*$)
isinstancerF   Strrematchs)argr   r   r   _is_identifier   s    rf   c             C   s\   t | tjr| jS t | tjr(t| jS yt| jd | j S  t	k
rV   t| jS X d S )N.)
r`   rF   NameidCall_to_name_strfuncvaluer[   AttributeError)r   r   r   r   rk      s    
rk   c             c   sh   t | tjr| jV  nNt | tjr4t| jE d H  n0t | tjtjfrdx| j	D ]}t|E d H  qNW d S )N)
r`   rF   rh   ri   Starrednames_from_assignmentsrm   ListTupleelts)Zassign_targetchildr   r   r   rp      s    
rp   c             c   s6   | V  t | ts2x t| D ]}t|E d H  qW d S )N)r`   FUNCTION_NODESrF   iter_child_nodeschildren_in_scope)r   rt   r   r   r   rw      s    
rw   c             C   s$   y
t | |S  tk
r   dS X d S )NF)
issubclass	TypeError)r?   class_or_tupler   r   r   _typesafe_issubclass   s    
r{   c                   s  e Zd Ze Ze ZejeedZ	ejee
dZejee
dZejee
dZejeedZejee
dZdZejeddZedd Z fddZd	d
 Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Z d#d$ Z!d%d& Z"d'd( Z#d)d* Z$d+d, Z%d-d. Z&d/d0 Z'd1d2 Z(d3d4 Z)d5d6 Z*d7d8 Z+d9d: Z,d;d< Z-d=d> Z.d?d@ Z/dAdB Z0dCdD Z1e2j3dEdFdGZ4e2j5dHdIdJZ6dKdL Z7dMdN Z8dOdP Z9dQdR Z:dSdT Z;dUdV Z<dWdX Z=dYdZ Z>d[d\ Z?d]d^ Z@d_d` ZA  ZBS )ar   )r   r   F)factoryr   c             C   s$   t | jdkrg S | jd \}}|S )Nr   r.   )r3   contexts)r'   contextr	   r   r   r   
node_stack   s    zBugBearVisitor.node_stackc                sx   t |t}|r$t|g }| j| | j| | j| | j| j d  | _t 	| | j
  |rt| j
  d S )N)r`   CONTEXTFUL_NODESr   r}   appendr   node_windowNODE_WINDOW_SIZEsuperr   pop)r'   r   Zis_contextfulr~   )	__class__r   r   r     s    


zBugBearVisitor.visitc       
         s  |j d kr(| jt|j|jdd nt|j tjrdd |j j	D }|j
d k	r^d|j
 nd}t|dkrd| d	f}| jt|j|j|d n t|d
kr| jt|j|j|d ntt||jd}d|krdg}x0tj D ]"\} ||kr fdd|D }qW xNtt|dD ]:\}}ttt|t tt|dr&||kr&|| q&W ||krt|d
kr|d ndd|}	| jt|j|jd|||	fd | | d S )N)zbare `except:`)r0   c             S   s   g | ]}t |qS r   )rk   ).0r(   r   r   r   
<listcomp>  s    z6BugBearVisitor.visit_ExceptHandler.<locals>.<listcomp>z as rB   r   z
`except ()z:`r*   )keyBaseExceptionc                s   g | ]}| kr|qS r   r   )r   g)equivalentsr   r   r   1  s    r,   r   z({})z, )typer"   r   B001r8   
col_offsetr`   rF   rr   rs   rX   r3   B013sortedr   indexB014redundant_exceptionsitemsr    permutationstupler{   getattrbuiltinsremover>   rH   generic_visit)
r'   r   namesZas_vsZgoodprimaryrX   otherdescr   )r   r   visit_ExceptHandler  s<    


&z"BugBearVisitor.visit_ExceptHandlerc             C   s^   t tt| jdd  }|tjtjtjtjgkrP| jd }| jt	|j
|j | | d S )N)listmapr   r   rF   UnaryOpUAddr"   r   B002r8   r   r   )r'   r   Ztrailing_nodesZ
originatorr   r   r   
visit_UAddD  s
    
zBugBearVisitor.visit_UAddc          	   C   sB  t |jtjr| | nttt |jjdkrZ|j	d j
dkrZ| jt|j|j |jjdkrt|j	dkrt|j	d rt|j	d j
s| jt|j|j nltdd | jD s|jjdkrt|j	d	krt|j	d rt|j	d j
s| jt|j|j W d Q R X | | | | | | d S )
N)r   r   r*   __call__r   r,   c             s   s   | ]}t |tjV  qd S )N)r`   rF   Lambda)r   nr   r   r   	<genexpr>]  s    z,BugBearVisitor.visit_Call.<locals>.<genexpr>setattr   )r`   rl   rF   	Attributecheck_for_b005r   rn   
IndexErrorri   argsrd   r"   r   B004r8   r   r3   rf   r   B009anyr   B010check_for_b026check_for_b905r   )r'   r   r   r   r   
visit_CallK  s(     

zBugBearVisitor.visit_Callc             C   sh   t |jdkrZ|jd }t|tjrZt|jtjrZ|jj|jfdkrZ| j	
t|j|j | | d S )Nr*   r   )osenviron)r3   targetsr`   rF   r   rm   rh   ri   r[   r"   r   B003r8   r   r   )r'   r   tr   r   r   visit_Assignj  s    
zBugBearVisitor.visit_Assignc             C   s,   |  | | | | | | | d S )N)check_for_b007check_for_b020check_for_b023r   )r'   r   r   r   r   	visit_Forr  s    


zBugBearVisitor.visit_Forc             C   s   |  | | | d S )N)r   r   )r'   r   r   r   r   visit_AsyncForx  s    
zBugBearVisitor.visit_AsyncForc             C   s   |  | | | d S )N)r   r   )r'   r   r   r   r   visit_While|  s    
zBugBearVisitor.visit_Whilec             C   s   |  | | | d S )N)r   r   )r'   r   r   r   r   visit_ListComp  s    
zBugBearVisitor.visit_ListCompc             C   s   |  | | | d S )N)r   r   )r'   r   r   r   r   visit_SetComp  s    
zBugBearVisitor.visit_SetCompc             C   s   |  | | | d S )N)r   r   )r'   r   r   r   r   visit_DictComp  s    
zBugBearVisitor.visit_DictCompc             C   s   |  | | | d S )N)r   r   )r'   r   r   r   r   visit_GeneratorExp  s    
z!BugBearVisitor.visit_GeneratorExpc             C   s   |  | | | d S )N)check_for_b011r   )r'   r   r   r   r   visit_Assert  s    
zBugBearVisitor.visit_Assertc             C   s"   |  | | | | | d S )N)check_for_b902check_for_b006_and_b008r   )r'   r   r   r   r   visit_AsyncFunctionDef  s    

z%BugBearVisitor.visit_AsyncFunctionDefc             C   sJ   |  | | | | | | | | | | | | | d S )N)check_for_b901r   r   check_for_b018check_for_b019check_for_b021r   )r'   r   r   r   r   visit_FunctionDef  s    





z BugBearVisitor.visit_FunctionDefc             C   s6   |  | | | | | | | | | d S )N)check_for_b903r   r   check_for_b024_and_b027r   )r'   r   r   r   r   visit_ClassDef  s
    



zBugBearVisitor.visit_ClassDefc             C   s"   |  | | | | | d S )N)check_for_b012check_for_b025r   )r'   r   r   r   r   	visit_Try  s    

zBugBearVisitor.visit_Tryc             C   s   |  | | | d S )N)check_for_b015r   )r'   r   r   r   r   visit_Compare  s    
zBugBearVisitor.visit_Comparec             C   s"   |  | | | | | d S )N)check_for_b016check_for_b904r   )r'   r   r   r   r   visit_Raise  s    

zBugBearVisitor.visit_Raisec             C   s"   |  | | | | | d S )N)check_for_b017check_for_b022r   )r'   r   r   r   r   
visit_With  s    

zBugBearVisitor.visit_Withc             C   s   |j jtjkrd S t|jdks2t|jd tjs6d S d	t
|j j}|tjkrVd S |jd j}t|dkrrd S t|tt|krd S | jt|j|j d S )Nr*   r   rg   )rl   r[   B005methodsr3   r   r`   rF   ra   rH   compose_call_pathrm   valid_pathsrd   r   r"   r   r8   r   )r'   r   	call_pathrd   r   r   r   r     s     
zBugBearVisitor.check_for_b005c             C   s2   t | j}||jj|jj  | j|j d S )N)FuntionDefDefaultsVisitorr   r   r   defaultskw_defaultsr"   extend)r'   r   r   r   r   r   r     s    
z&BugBearVisitor.check_for_b006_and_b008c       	      C   s   t  }||j ttdd |j}t  }x|jD ]}|| q4W t|j}x>t|| D ].}|j| d }| j	t
|j|j|fd q^W d S )Nc             S   s   |  d S )N_)r2   )rd   r   r   r   r     r   z/BugBearVisitor.check_for_b007.<locals>.<lambda>r   )r0   )
NameFinderr   targetr   filterr   bodyr   r"   r   B007r8   r   )	r'   r   r   
ctrl_namesr   exprZ
used_namesrX   r   r   r   r   r     s    
zBugBearVisitor.check_for_b007c             C   s4   t |jtjr0|jjdkr0| jt|j|j	 d S )NF)
r`   testrF   NameConstantrm   r"   r   B011r8   r   )r'   r   r   r   r   r     s    zBugBearVisitor.check_for_b011c                s8    fdd x$|j D ]} |tjtjtjf qW d S )Nc                st   t | tjtjfrd S t | tjtjfr2tjf}n t | |rRjt	| j
| j xt| D ]} || q^W d S )N)r`   rF   AsyncFunctionDefFunctionDefWhileForReturnr"   r   B012r8   r   rv   )r   Zbad_node_typesrt   )_loopr'   r   r   r     s    

z,BugBearVisitor.check_for_b012.<locals>._loop)Z	finalbodyrF   r   ContinueBreak)r'   r   rt   r   )r   r'   r   r     s    zBugBearVisitor.check_for_b012c             C   s,   t | jd tjr(| jt|j|j d S )N)	r`   r   rF   Exprr"   r   B015r8   r   )r'   r   r   r   r   r     s    zBugBearVisitor.check_for_b015c             C   s2   t |jtjtjtjfr.| jt|j	|j
 d S )N)r`   excrF   r   Numra   r"   r   B016r8   r   )r'   r   r   r   r   r     s    zBugBearVisitor.check_for_b016c             C   s   |j d }|j}t|dr~t|jdr~|jjdkr~t|jdkr~t|jd tj	r~|jd j
dkr~|js~| jt|j|j dS )a  Checks for use of the evil syntax 'with assertRaises(Exception):'

        This form of assertRaises will catch everything that subclasses
        Exception, which happens to be the vast majority of Python internal
        errors, including the ones raised when a non-existing method/function
        is called, or a function is called with an invalid dictionary key
        lookup.
        r   rl   r[   assertRaisesr*   	ExceptionN)r   context_exprr   rl   r[   r3   r   r`   rF   rh   ri   Zoptional_varsr"   r   B017r8   r   )r'   r   itemitem_contextr   r   r   r     s    	

zBugBearVisitor.check_for_b017c             C   s   t |jdks0t | jdk s0t| jd jtjs4d S dd |jD }xPt|D ]D\}}|dkrbd S |tj	krN| j
t|j| j|j| j d S qNW d S )Nr   r,   r   c             s   s   | ]}d  t|V  qdS )rg   N)rH   r   )r   	decoratorr   r   r   r     s    z0BugBearVisitor.check_for_b019.<locals>.<genexpr>>   r^   r_   )r3   decorator_listr}   r`   r   rF   ClassDefr1   B019cachesr"   r   r8   r   )r'   r   Zresolved_decoratorsidxr  r   r   r   r     s    

zBugBearVisitor.check_for_b019c             C   s   t  }||j t|j}t }||j t|j}xBt|D ]6}||krB|j| d }| j	t
|j|j|fd qBW d S )Nr   )r0   )r   r   r   r   r   B020NameFinderiterr   r"   r   B020r8   r   )r'   r   r   r   ZitersetZiterset_namesrX   r   r   r   r   r   .  s    

zBugBearVisitor.check_for_b020c          	   C   sR  g }g }x t |D ]}t|t jrt|jt jrB|jjdkszt|jt jr|jjdkrt|jj	t jr|jj	jdkrx"|j
D ]}t|tr|| qW x0|jD ]&}|jdkrt|j	tr||j	 qW t|t jrt|j	tr||j	 t|tr||krdd t |j
D }t|t jr8t |j}ntjtt j|j}g }	xr|D ]j}
t|
t jrX|
j|krXt|
jt jr|	t|
j|
j|
jfd nt|
jt jrX||
j qXW x@|	D ]8}|jd |kr|| jkr| j| || qW qW |r t|  |}x,t!|D ] }|"|jr*| j#| q*W d	S )
a8  Check that functions (including lambdas) do not use loop variables.

        https://docs.python-guide.org/writing/gotchas/#late-binding-closures from
        functions - usually but not always lambdas - defined inside a loop are a
        classic source of bugs.

        For each use of a variable inside a function defined inside a loop, we
        emit a warning if that variable is reassigned on each loop iteration
        (outside the function).  This includes but is not limited to explicit
        loop variables like the `x` in `for x in range(3):`.
        )r   reducer   r  	functoolsr   c             S   s   h | ]}t |tjr|jqS r   )r`   rF   re   )r   re   r   r   r   	<setcomp>o  s   z0BugBearVisitor.check_for_b023.<locals>.<setcomp>)r0   r   N)$rF   walkr`   rj   rl   rh   ri   r   r[   rm   r   ru   r   keywordsre   r   r   r   r    r!   from_iterabler   ctxLoadB023r8   r   Storeaddr0   
_b023_seenr   _get_assigned_namesr   
issupersetr"   )r'   	loop_nodeZsafe_functionsZsuspicious_variablesr   re   keywordargnamesZ
body_nodesr"   rX   errZreassigned_in_loopr   r   r   r   <  sV    



zBugBearVisitor.check_for_b023)r   c                s  d fdd	 dd }dd }t dd	d
}t|jt|j dkrHdS tt |j|jsbdS d}x|jD ]}t|tj	tj
frd}qnt|tjtjfsqntt||j}||O }|sn||jrntt||jsn| jt|j|j|jfd qnW |s| jt|j|j|jfd dS )zkCheck for inheritance from abstract classes in abc and lack of
        any methods decorated with abstract*ABCc                sh   t | tjr"| jdko  | jdS t | tjr8| j|kpft | tjof| j|koft | jtjof| jjdkS )N	metaclassABCMetaabc)	r`   rF   r#  re   rm   rh   ri   r   r[   )rm   rX   )is_abc_classr   r   r*    s    
z<BugBearVisitor.check_for_b024_and_b027.<locals>.is_abc_classc             S   s<   t | tjr| jd d dkp:t | tjo:| jd d dkS )N   Zabstract)r`   rF   rh   ri   r   r[   )r   r   r   r   is_abstract_decorator  s    zEBugBearVisitor.check_for_b024_and_b027.<locals>.is_abstract_decoratorc             S   s,   t | tjr| jdkp*t | tjo*| jdkS )Noverload)r`   rF   rh   ri   r   r[   )r   r   r   r   is_overload  s    z;BugBearVisitor.check_for_b024_and_b027.<locals>.is_overload)returnc                s   dd  t  fdd| D S )Nc             S   s4   t | tjtjfp2t | tjo2| jtkp2t | jtS )N)r`   rF   Ellipsisra   Constantrm   str)r   r   r   r   is_str_or_ellipsis  s    zVBugBearVisitor.check_for_b024_and_b027.<locals>.empty_body.<locals>.is_str_or_ellipsisc             3   s0   | ](}t |tjp&t |tjo& |jV  qd S )N)r`   rF   Passr   rm   )r   stmt)r3  r   r   r     s   zMBugBearVisitor.check_for_b024_and_b027.<locals>.empty_body.<locals>.<genexpr>)all)r   r   )r3  r   
empty_body  s    
z:BugBearVisitor.check_for_b024_and_b027.<locals>.empty_bodyr*   NFT)r0   )r&  )boolr3   basesr  r   r   r   r`   rF   	AnnAssignAssignr   r   r  r"   r   B027r8   r   rX   B024)r'   r   r,  r.  r7  Zhas_abstract_methodr5  Zhas_abstract_decoratorr   )r*  r   r     s2    
z&BugBearVisitor.check_for_b024_and_b027)callc             C   sn   |j s
d S dd |jD }|s"d S |j d j}x:|D ]2}|j|jf|j|jfkr4| jt|j|j q4W d S )Nc             S   s   g | ]}t |tjr|qS r   )r`   rF   ro   )r   re   r   r   r   r     s    z1BugBearVisitor.check_for_b026.<locals>.<listcomp>r   )r  r   rm   r8   r   r"   r   B026)r'   r>  ZstarredsZfirst_keywordZstarredr   r   r   r     s    


zBugBearVisitor.check_for_b026c             c   sv   t jt jt jf}x`t|D ]T}t|t jrHx|jD ]}t|E d H  q2W t||t j	t j
f rt|jE d H  qW d S )N)rF   r   AsyncForcomprehensionrw   r`   r;  r   rp   r:  	AugAssignr   )r'   r"  Zloop_targetsr   rt   r   r   r   r     s    z"BugBearVisitor._get_assigned_namesc             C   s\   |j dkrX|jdk	rXt|jtjr.|jj sXtdd | jD rX| j	
t|j|j dS )a  Checks `raise` without `from` inside an `except` clause.

        In these cases, you should use explicit exception chaining from the
        earlier error, or suppress it with `raise ... from None`.  See
        https://docs.python.org/3/tutorial/errors.html#exception-chaining
        Nc             s   s   | ]}t |tjV  qd S )N)r`   rF   ExceptHandler)r   r   r   r   r   r     s    z0BugBearVisitor.check_for_b904.<locals>.<genexpr>)causer  r`   rF   rh   ri   islowerr   r   r"   r   B904r8   r   )r'   r   r   r   r   r     s
    

zBugBearVisitor.check_for_b904c             #   s0    fdd x|j D ]} ||E d H  qW d S )Nc             3   sH   t |tjtjfrd S | |fV  x"t|D ]} ||E d H  q,W d S )N)r`   rF   r   r   rv   )parentr   rt   )r   r   r   r     s
    
z0BugBearVisitor.walk_function_body.<locals>._loop)r   )r'   r   rt   r   )r   r   walk_function_body  s    z!BugBearVisitor.walk_function_bodyc             C   s   |j dkrd S d}d }xv| |D ]h\}}t|tjrLt|tjtjfrLd}t|tjrf|jd k	rf|}|r"|d k	r"| j	
t|j|j P q"W d S )N	__await__FT)rX   rH  r`   rF   r   Yield	YieldFromr   rm   r"   r   B901r8   r   )r'   r   Z	has_yieldZreturn_noderG  xr   r   r   r     s    
zBugBearVisitor.check_for_b901c          	   C   s  t | jdk s"t| jd jtjs&d S | jd j}t }||j d|j	krRd S dd |j
D }d|krd|j	ks|jtjkrtj}d}qtj}d	}n,d|j	ks|jtjkrtj}d
}n
tj}d}t|jdg |jj }|jj}|jj}	|jj}
|r|d j}|d j}|d j}nv|r6d|j }|j}|j}nX|	rTd|	j }|	j}|	j}n:|
r~d|
d j }|
d j}|
d j}nd}|j}|j}||kr|dst|}| jt|||||d fd d S )Nr,   r   r_   c             S   s   h | ]}t |tjr|jqS r   )r`   rF   rh   ri   )r   br   r   r   r  4  s    z0BugBearVisitor.check_for_b902.<locals>.<setcomp>r   r^   zmetaclass classzmetaclass instanceclassinstanceZposonlyargsr   *z**z*, z(none))(rQ  )r0   )r3   r}   r`   r   rF   r  r   r   r  r   r9  rX   B902implicit_classmethodsmetaclsr?   r'   r   r   varargkwarg
kwonlyargsre   r8   r   r2   reprr"   r   )r'   r   r?   Z
decoratorsr9  Zexpected_first_argskindr   rV  rW  rX  Zactual_first_argr8   colr   r   r   r   %  sd    








zBugBearVisitor.check_for_b902c             C   s   |j }|r8t|d tjr8t|d jtjr8|dd  }t|dksbt|d tjrb|d jdkrfd S xZ|d j D ]L}t|tj	sd S |j
}t|dkst|d tjsd S t|jtjsrd S qrW | jt|j|j d S )Nr   r*   __init__)r   r`   rF   r   rm   ra   r3   r   rX   r;  r   r   rh   r"   r   B903r8   r   )r'   r   r   r5  r   r   r   r   r   k  s$    zBugBearVisitor.check_for_b903c          	   C   s\   xV|j D ]L}t|tjsqt|jtjtjtjtjtj	tj
fr| jt|j|j qW d S )N)r   r`   rF   r   rm   r  Bytesr   rq   SetDictr"   r   B018r8   r   )r'   r   Zsubnoder   r   r   r     s    
zBugBearVisitor.check_for_b018c             C   sV   |j rRt|j d tjrRt|j d jtjrR| jt|j d jj	|j d jj
 d S )Nr   )r   r`   rF   r   rm   	JoinedStrr"   r   B021r8   r   )r'   r   r   r   r   r     s
    zBugBearVisitor.check_for_b021c             C   s   |j d }|j}t|dr~t|jdr~t|jjdr~|jjjdkr~t|jdr~|jjdkr~t|jdkr~| j	
t|j|j d S )Nr   rl   rm   ri   
contextlibr[   r   )r   r  r   rl   rm   ri   r[   r3   r   r"   r   B022r8   r   )r'   r   r	  r
  r   r   r   r     s    

zBugBearVisitor.check_for_b022c                s   g  x|j D ]|}t|jtjtjfr@dt|j} | qt|jtj	rt
 }x(|jjD ]}dt|}|| q^W  | qW t fdd D }x(|D ] }| jt|j|j|fd qW d S )Nrg   c                s   h | ]}  |d kr|qS )r*   )count)r   rM  )seenr   r   r    s    z0BugBearVisitor.check_for_b025.<locals>.<setcomp>)r0   )handlersr`   r   rF   rh   r   rH   r   r   rr   r   rs   r  r   r   r"   B025r8   r   )r'   r   handlerrX   Zuniquesentry
duplicatesZ	duplicater   )rg  r   r     s    
zBugBearVisitor.check_for_b025c             C   sH   t |jtjrD|jjdkrDtdd |jD sD| jt	|j
|j d S )Nzipc             s   s   | ]}|j d kV  qdS )strictN)re   )r   kwr   r   r   r     s    z0BugBearVisitor.check_for_b905.<locals>.<genexpr>)r`   rl   rF   rh   ri   r   r  r"   r   B905r8   r   )r'   r   r   r   r   r     s    zBugBearVisitor.check_for_b905)CrU   rV   rW   r[   r\   r   r   r]   r   r   r   r   r   r"   futuresr}   r   r  propertyr   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   rF   r  r   rj   r   r   r   rH  r   r   r   r   r   r   r   r   __classcell__r   r   )r   r   r      sn   	2	OR	F
r   c             c   s\   t | tjr&t| jE d H  | jV  n2t | tjrDt| jE d H  nt | tjrX| j	V  d S )N)
r`   rF   r   r   rm   r[   rj   rl   rh   ri   )r   r   r   r   r     s    
r   c                   s:   e Zd ZdZejeedZdd Z	 fddZ
  ZS )r   zFinds a name within a tree of nodes.

    After `.visit(node)` is called, `found` is a dict with all name nodes inside,
    key is name string, value is the node (useful for location purposes).
    )r   c             C   s   | j |jg | d S )N)r   
setdefaultri   r   )r'   r   r   r   r   
visit_Name  s    zNameFinder.visit_Namec                s4   t |tst |S x|D ]}t | qW |S )z3Like super-visit but supports iteration over lists.)r`   r   r   r   )r'   r   elem)r   r   r   r     s
    

zNameFinder.visit)rU   rV   rW   __doc__r[   r\   r]   dictr   ru  r   rs  r   r   )r   r   r     s   r   c                   sB   e Zd Zd fdd	Zdd Zdd Zdd	 Z fd
dZ  ZS )r   Nc                sP   |pt  | _x(tjtj D ]}t| d| | j qW g | _d| _t	 
  d S )Nvisit_r   )r   r   B006mutable_literalsmutable_comprehensionsr   &visit_mutable_literal_or_comprehensionr"   	arg_depthr   r\  )r'   r   r   )r   r   r   r\    s    z"FuntionDefDefaultsVisitor.__init__c             C   s.   | j dkr | jt|j|j | | d S )Nr*   )r~  r"   r   rz  r8   r   r   )r'   r   r   r   r   r}    s    
z@FuntionDefDefaultsVisitor.visit_mutable_literal_or_comprehensionc             C   s   d t|j}|tjkr>| jt|j|j | 	| d S |t
j| jB kr\| 	| d S |dkrt|jdkrytt|jd }W n tk
r   Y qX t|r| jt
|j|j n| jt
|j|j | 	| d S )Nrg   floatr*   r   )rH   r   rl   rz  mutable_callsr"   r   r8   r   r   B008immutable_callsr   r3   r   r  rF   literal_evalr  mathisfinite)r'   r   r   rm   r   r   r   r     s"    



z$FuntionDefDefaultsVisitor.visit_Callc             C   s   d S )Nr   )r'   r   r   r   r   visit_Lambda!  s    z&FuntionDefDefaultsVisitor.visit_Lambdac                sZ   |  j d7  _ t|tr<x.|D ]}|dk	rt | qW nt | |  j d8  _ dS )z3Like super-visit but supports iteration over lists.r*   N)r~  r`   r   r   r   )r'   r   rv  )r   r   r   r   &  s    

zFuntionDefDefaultsVisitor.visit)N)	rU   rV   rW   r\  r}  r   r  r   rs  r   r   )r   r   r     s
   r   c               @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )r  z?Ignore names defined within the local scope of a comprehension.c             C   s   |  |j d S )N)r   
generators)r'   r   r   r   r   r   5  s    z!B020NameFinder.visit_GeneratorExpc             C   s   |  |j d S )N)r   r  )r'   r   r   r   r   r   8  s    zB020NameFinder.visit_ListCompc             C   s   |  |j d S )N)r   r  )r'   r   r   r   r   r   ;  s    zB020NameFinder.visit_DictCompc             C   s   |  |j d S )N)r   r  )r'   r   r   r   r   visit_comprehension>  s    z"B020NameFinder.visit_comprehensionc             C   s2   |  |j x |jjD ]}| j|jd  qW d S )N)r   r   r   r   r   re   )r'   r   Z
lambda_argr   r   r   r  A  s    zB020NameFinder.visit_LambdaN)	rU   rV   rW   rw  r   r   r   r  r  r   r   r   r   r  2  s   r  errorzlineno col message type varsr   )r   r0   zB001 Do not use {}, it also catches unexpected events like memory errors, interrupts, system exit, and so on.  Prefer `except Exception:`.  If you're sure what you're doing, be explicit and write `except BaseException:`.)r%   zB002 Python does not support the unary prefix increment. Writing ++n is equivalent to +(+(n)), which equals n. You meant n += 1.zB003 Assigning to `os.environ` doesn't clear the environment. Subprocesses are going to see outdated variables, in disagreement with the current process. Use `os.environ.clear()` or the `env=` argument to Popen.zB004 Using `hasattr(x, '__call__')` to test if `x` is callable is unreliable. If `x` implements custom `__getattr__` or its `__call__` is itself not callable, you might get misleading results. Use `callable(x)` for consistent results.zB005 Using .strip() with multi-character strings is misleading the reader. It looks like stripping a substring. Move your character set to a constant if this is deliberate. Use .replace() or regular expressions to remove string fragments.lstriprstripr5   zB006 Do not use mutable data structures for argument defaults.  They are created during function definition time. All calls to the function reuse this one instance of that data structure, persisting changes between them.)r`  rq   r_  )ListCompDictCompSetCompCounterOrderedDictzcollections.Counterzcollections.OrderedDictzcollections.defaultdictzcollections.dequedefaultdictdequerx  r   r   zvB007 Loop control variable {!r} not used within the loop body. If this is intended, start the name with an underscore.aB  B008 Do not perform function calls in argument defaults.  The call is performed only once at function definition time. All calls to your function will reuse the result of that definition-time function call.  If this is intended, assign the function call to a module-level variable and use that variable as a default value.r   	frozensetztypes.MappingProxyTypeMappingProxyTypez
re.compilezoperator.attrgetterzoperator.itemgetterzoperator.methodcaller
attrgetter
itemgettermethodcallerzjB009 Do not call getattr with a constant attribute value, it is not any safer than normal property access.zjB010 Do not call setattr with a constant attribute value, it is not any safer than normal property access.zqB011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().zB012 return/continue/break inside finally blocks cause exceptions to be silenced. Exceptions should be silenced in except blocks. Control statements can be moved outside the finally block.z_B013 A length-one tuple literal is redundant.  Write `except {0}:` instead of `except ({0},):`.zyB014 Redundant exception types in `except ({0}){1}:`.  Write `except {2}{1}:`, which catches exactly the same exceptions.IOErrorEnvironmentErrorZWindowsErrorz
mmap.errorzsocket.errorzselect.errorzbinascii.Error)OSError
ValueErrorzoB015 Result of comparison is not used. This line doesn't do anything. Did you intend to prepend it with assert?zOB016 Cannot raise a literal. Did you intend to return it or raise an Exception?a!  B017 assertRaises(Exception): should be considered evil. It can lead to your test passing even if the code being tested is never executed due to a typo. Either assert for a more specific exception (builtin or custom), use assertRaisesRegex, or use the context manager form of assertRaises.zYB018 Found useless expression. Consider either assigning it to a variable or removing it.zB019 Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks. The cache may retain instance references, preventing garbage collection.zfunctools.cachezfunctools.lru_cachecacher   zYB020 Found for loop that reassigns the iterable it is iterating with each iterable value.zoB021 f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring.zB022 No arguments passed to `contextlib.suppress`. No exceptions will be suppressed and therefore this context manager is redundant.z:B023 Function definition does not bind loop variable {!r}.zB024 {} is an abstract base class, but it has no abstract methods. Remember to use the @abstractmethod decorator, potentially in conjunction with @classmethod, @property and/or @staticmethod.zB025 Exception `{0}` has been caught multiple times. Only the first except will be considered and all other except catches can be safely removed.zB026 Star-arg unpacking after a keyword argument is strongly discouraged, because it only works when the keyword parameter is declared after all parameters supplied by the unpacked sequence, and this change of ordering can surprise and mislead readers.zuB027 {} is an empty method in an abstract base class, but has no abstract decorator. Consider adding @abstractmethod.zB901 Using `yield` together with `return x`. Use native `async def` coroutines or put a `# noqa` comment on this line if this was intentional.zmB902 Invalid first argument {} used for {} method. Use the canonical first argument name in methods, i.e. {}.__new____init_subclass____class_getitem__r'   r?   klassrU  r'  typmcszB903 Data class should either be immutable or use __slots__ to save memory. Use collections.namedtuple to generate an immutable class, or enumerate the attributes in a __slot__ declaration in the class to leave attributes mutable.zB904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling.  See https://docs.python.org/3/tutorial/errors.html#exception-chaining for details.z5B905 `zip()` without an explicit `strict=` parameter.z'B950 line too long ({} > {} characters)rL  rS  r]  rF  rp  r7   )]rF   r   r    loggingr  rb   collectionsr   rd  r   r  r   r   r#  r   r[   rC   rY   	getLoggerrO   Moduler  r   r   r   r  r  r  GeneratorExpr   ru   r   rd   r   rf   rk   rp   rw   r{   NodeVisitorr   r   r   r   r  r  Errorr   r   r   r   r   r   r   rz  r{  r|  r  r   r  r  r   r   r   r   r   r   r   r  r  r  ra  r  r  r  rc  re  r  r=  ri  r?  r<  rL  rS  rT  r'   r?   rU  r]  rF  rp  r7   rK   r   r   r   r   <module>   s,  
 



     l

D




