³ò
C3IHc        	   @   s?  d  d k  l Z d  d k l Z l Z d  d k l Z d  d k Td  d k l	 Z	 d  d k
 l Z l Z d „  Z d „  Z d	 „  Z d
 e f d „  ƒ  YZ d „  Z d „  Z d e f d „  ƒ  YZ d „  Z d e f d „  ƒ  YZ d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   Check(   t   Optt   BoolOpt(   t   Warning(   t   *(   t   symbols(   t   astt   walkc         C   s&   |  i  t i j o |  i i  t i j S(   N(   t	   __class__R   t   FunctionScopet   parentt
   ClassScope(   t   scope(    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyt
   _is_method	   s    c         C   s!   t  |  ƒ o | |  i i d  j S(   Ni   (   R   t   nodet   argnames(   R   t   name(    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyt   _is_self   s    c      
   C   s÷   t  | t i ƒ oà |  | i i j oÉ | i i o¼ | i i } | i i o | d  } n | i i o | d  } n | t | i i ƒ } yH | i i | i	 |  ƒ } t  | t
 i ƒ o | i |  j o d Sn Wqï t j
 o qï Xqó n d  S(   Niÿÿÿÿi   (   t
   isinstanceR   R	   R   R   t   defaultst   kwargst   varargst   lent   indexR   t   NameR   t
   ValueErrort   None(   R   R   t   argst   default(    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyt!   is_arg_and_defaulted_to_same_name   s      t   ShadowCheckc           B   sG   e  Z d  Z e d d ƒ Z e d d d ƒ Z e d d ƒ Z d „  Z RS(	   s`   Use symbol information to check that no scope defines a name
    already known to a parent scopes   Report any redefinition of Nones   Do not redefine Nones!   Report names that shadow builtinss   Identifier (%s) shadows builtini    s,   Report names already defined in outer scopess.   Identifier (%s) shadows definition in scope %sc         C   s<  x5| i  ƒ  D]'\ } } x| i D]} | d j o! | i | i | |  i ƒ q# n | | i j o q# n t | | ƒ o q# n t | | ƒ o q# n t i | ƒ o! | i | i | |  i	 | ƒ n x` t
 | ƒ D]R } | i i | ƒ o9 t | t i ƒ o% | i | i | |  i | | ƒ qÚ qÚ Wq# Wq Wd  S(   NR   (   t   not_class_scopest   defst   warningt
   defineNonet   globalsR   R   t   __builtins__t   has_keyt   shadowBuiltinst   parentsR   R   R   t   shadowIdentifier(   t   selft   filet   unused_checkerR   R   R   t   p(    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyt   check3   s*     
 ! (   t   __name__t
   __module__t   __doc__R   R"   R&   R(   R-   (    (    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyR   )   s   		c         C   s+   t  |  ƒ t  d ƒ j o t |  ƒ Sn |  S(   Nt    (   t   typet   eval(   t   s(    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyt
   _str_valueI   s    c         C   s  |  p d Sn |  d } t  | t i ƒ o d Sn t |  ƒ d j o t  | t i ƒ o d Sn t |  ƒ d j o1 t  | t i ƒ o t  | i t i ƒ o d Sn t  | t i ƒ oY t  | i	 t i ƒ o | i	 i p) t  | i	 t i
 ƒ o | i	 i d j o d Sqn d S(   Ni   i    R   (   R   R   t   RaiseR   t   Passt   Returnt   valuet   Constt   Assertt   testR   R   (   t   stmtst   stmt(    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyt   _empty_functionO   s    
&)$)t   UnusedCheckc           B   s8   e  Z d  Z e d d ƒ Z d „  Z d „  Z d „  Z RS(   sd   Use symbol information to check that no scope defines a name
    not used in this or any child scopes   Report names not useds   Identifier (%s) not usedc         C   s   d  |  _ d  |  _ d  S(   N(   R   t   reportUnusedSelft   unusedPrefixes(   R)   (    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyt   __init__j   s    	c         C   s`   d } d d d d d d d g } | i  t |  d	 | | ƒ ƒ d
 } | i  t |  d | ƒ ƒ d  S(   Ns6   Ignore unused identifiers that start with these valuest   unusedt   emptyt   dummyt   __pychecker__t   __all__t   __version__t   ignoredRB   s%   Ignore unused method "self" parameterRA   (   t   addR   R   (   R)   t   optionst   descR   (    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyt   get_optionsn   s    	c      	      sn  t  |  i ƒ |  _ ‡  f d †  ‰  xF| i ƒ  D]8\ } } t | t i ƒ o t | i i ƒ o q. qk n xø | i	 D]í } | d j o qu n |  i
 o t | | ƒ o qu n | | i j o2 | i i | ƒ p | i d ƒ p qu qï qó n xl |  i D] } | i | ƒ o Pqý qý Wˆ  | | ƒ o5 | i i | ƒ o! | i | i	 | |  i | ƒ qu qu Wq. Wd  S(   Nc            sN   | i  i |  ƒ o d Sn x, | i ƒ  D] } ˆ  |  | ƒ o d Sq( q( Wd S(   Ni   i    (   t   usesR%   t   get_children(   R   t   parent_scopet   c(   t   used(    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyRS   z   s     t   _(   R5   RB   R   R   R   t   FunctionR?   t   codet   nodesR    RA   R   t
   root_scopet   importsR%   t
   startswithR#   R!   RD   (   R)   R*   R+   RW   R   t   vart   prefix(    (   RS   s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyR-   w   s.     
 
 	%(   R.   R/   R0   R   RD   RC   RN   R-   (    (    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyR@   d   s
   			c         C   s=   |  i  i | ƒ o d Sn |  i o t |  i | ƒ Sn d  S(   Ni   (   RY   R%   R
   t   _importedNameR   (   R   R   (    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyR]       s
    
t   UnknownCheckc           B   sY   e  Z d  Z e d d ƒ Z h  Z e i e ƒ e e d <e e d d ƒ e d <d „  Z
 RS(   s[   Use symbol information to check that no scope uses a name
    not defined in a parent scopes!   Report names that are not defineds   Unknown identifier: %sR$   t   WindowsErrorc         C   s¶   x¯ | i  i ƒ  D]ž } t | i | i ƒ } t | |  i ƒ } xn | D]f } x] t | ƒ D] } | i i | ƒ o PqW qW Wt | | ƒ p! | i	 | i | |  i
 | ƒ qD qD Wq Wd  S(   N(   t   scopest   valuest
   dict_minusRO   R    t   builtinsR'   R%   R]   R!   t   unknown(   R)   R*   R+   R   Rd   R[   R,   (    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyR-   ³   s       	N(   R.   R/   R0   R   Rd   Rc   t   updateR$   t   getattrR   R-   (    (    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyR^   §   s   	
c         C   sn   t  |  i ƒ } |  i o | d 8} n |  i o | d 8} n | d j o t  |  i ƒ | j o d Sn d  S(   Ni   i    (   R   R   R   R   R   R   (   t   function_nodet   count(    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyt   _first_arg_defaultedÁ   s    

#t	   SelfCheckc           B   s\   e  Z d  Z e d d ƒ Z e d d ƒ Z e d d ƒ Z e d d ƒ Z d	 „  Z d
 „  Z	 RS(   s   Check for simple self parameters3   Report any methods whose first argument is not selfs-   First argument to method %s (%s) is not in %ss,   Report a self parameter with a default values4   First argument to method %s (%s) has a default values:   Report functions (not methods) with arguments named "self"s!   Argument to function (%s) is "%s"s   Report methods without "self"s#   Method %s is missing self parameterc         C   sf   d } d d d g } | i  t |  d | | ƒ ƒ d } d g |  _ | i  t |  d | |  i ƒ ƒ d  S(   Ns   Name of self parameterR)   t   thisR4   t	   selfNamess   Suspicious self parameterst   selfSuspicious(   RK   R   Rm   (   R)   RL   RM   R   (    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyRN   Ú   s    c         C   sP  t  |  i ƒ |  _ t  |  i ƒ |  _ x%| i ƒ  D]\ } } | i } t | i d d ƒ } t | ƒ o› | p | i | i |  i	 | ƒ qH| d |  i j o+ | i | i |  i
 | | d |  i ƒ n t | i ƒ o$ | i | i |  i | | d ƒ qHq1 xB | D]: } | |  i j o$ | i | i | |  i | | ƒ q
q
Wq1 Wd  S(   NR   t   lambdai    (   R5   Rl   Rm   t   function_scopesR   Rf   R   R   R!   t   missingSelft   selfNameRi   t   selfDefaultR    t   functionSelf(   R)   R*   R+   R   R   R   R   t   arg(    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyR-   ã   s(     	 (
   R.   R/   R0   R   Rq   Rr   Rs   Rp   RN   R-   (    (    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyRj   Ë   s   						t   UnpackCheckc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s#   Mark all unpacked variables as usedc         C   s   d  |  _ d  S(   N(   R   t   unpackedUsed(   R)   (    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyRC   ÿ   s    c         C   s&   d } | i  t |  d | d ƒ ƒ d  S(   Ns7   Do not treat variables used in tuple assignment as usedRv   i   (   RK   R   (   R)   RL   RM   (    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyRN     s    c            sÃ   |  i  p d  Sn d d ‡  f d †  ƒ  Y} xm ˆ  i ƒ  D]_ \ } } xP t | i t ƒ D]< } x3 t i | ƒ D]" } | i i | | ƒ | i | <qm WqW Wq8 Wˆ  i	 o t
 ˆ  i	 i | ƒ  ƒ n d  S(   Nt   Visitorc              s   e  Z ‡  f d  †  Z e Z RS(   c            sj   xc | i  ƒ  D]U } xL t | ƒ D]> } y | ˆ  i | i | i <PWq  t t f j
 o q  Xq  Wq Wd  S(   N(   t   getChildNodesR'   R`   RO   R   t   KeyErrort   AttributeError(   R)   R   RR   t   n(   R*   (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyt   visitAssTuple  s      (   R.   R/   R|   t   visitAssList(    (   R*   (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyRw   
  s   (    (   Rv   Ro   t   type_filterR   t   tupleR   t   flattenRO   t   getRX   R   R   (   R)   R*   R+   Rw   t
   scope_nodeR   Rt   t   unpacked(    (   R*   s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyR-     s    
   (
(   R.   R/   R0   RC   RN   R-   (    (    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyRu   ü   s   		c         C   s0   g  } |  D] } | | j o | | q q ~ S(   N(    (   t   at   bt   _[1]t   i(    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyt
   intersect2  s    c         C   s2   |  d } x! |  d D] } t  | | ƒ } q W| S(   Ni    i   (   Rˆ   (   t   itemst   resultt   item(    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyt	   intersect!  s
    
 t   UsedBeforeSetCheckc           B   s    e  Z e d  d ƒ Z d „  Z RS(   s9   Report variables that may be used before they are defineds'   The local %s may be used before definedc   
         s¼   d t  f ‡  f d †  ƒ  Y‰  x™ | i ƒ  D]‹ \ } } t i | i ƒ | i i ƒ  } t | i ˆ  | ƒ ƒ } t	 | i
 | i ƒ } x0 | i ƒ  D]" \ } }	 | i |	 |  i | ƒ qŽ Wq) Wd  S(   NRw   c              sV   e  Z d d d  „ Z d „  Z e Z e Z d „  Z d „  Z d „  Z	 ‡  f d †  Z
 RS(   c         S   sQ   g  |  _  h  |  _ | d  j	 o | |  _  n | d  j	 o | i ƒ  |  _ n d  S(   N(   t   definesRO   R   t   copy(   R)   RŽ   RO   (    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyRC   /  s    		c         S   s   |  i  i | i ƒ d  S(   N(   RŽ   t   appendR   (   R)   R{   (    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyt   visitFunction8  s    c         S   s(   x! | i  D] } |  i i | ƒ q
 Wd  S(   N(   t   namesRŽ   R   (   R)   R   R   (    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyt   visitGlobal>  s    
 c         S   s>   t  i | i ƒ | i g } x | D] } |  i | ƒ q# Wd  S(   N(   R   t   flatten_nodest   qualst   exprt   visit(   R)   R{   t   childrenRR   (    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyt   visitListCompB  s     c         S   s=   | i  |  i j o& |  i i | i  | ƒ |  i | i  <n d  S(   N(   R   RŽ   RO   R   (   R)   R{   (    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyt	   visitNameH  s    c            sú   | i  p d  Sn g  } x< | i D]1 \ } } | i t | ˆ  |  i |  i ƒ ƒ ƒ q" W| i t | i  ˆ  |  i |  i ƒ ƒ ƒ t g  } | D] } | | i q ~ ƒ |  _ h  } | i ƒ  x | D] } | i | i ƒ qÃ W| i |  i ƒ | |  _ d  S(   N(	   t   else_t   testsR   R   RŽ   RO   RŒ   t   reverseRe   (   R)   R{   t   visitsR<   RV   R†   t   vt   union(   Rw   (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyt   visitIfL  s    

 )(-
 N(   R.   R/   R   RC   R‘   t
   visitClasst   visitAssNameR“   R™   Rš   R¡   (    (   Rw   (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyRw   .  s   					(   t   BaseVisitorRo   R   R€   t   paramsRY   t   keysR   RV   t   dict_intersectRO   R    R‰   R!   t   usedBeforeDefined(
   R)   R*   R+   R   R   t
   predefinedt   visitort
   usedBeforeR   t   use_node(    (   Rw   s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyR-   -  s    /  (   R.   R/   R   R¨   R-   (    (    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pyR   '  s   	N(   t   pychecker2.CheckR    t   pychecker2.OptionsR   R   t   pychecker2.WarningR   t   pychecker2.utilt
   pychecker2R   t   compilerR   R   R   R   R   R   R5   R?   R@   R]   R^   Ri   Rj   Ru   Rˆ   RŒ   R   (    (    (    s/   C:\py\_spe\plugins\pychecker2\VariableChecks.pys   <module>   s(   
			 		<		
1"		