
'![c           @   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 y d d l m Z Wn! e	 k
 r d d l
 m Z n Xd d l Z d d l Z d d l m Z d d l m Z d d l m Z m Z m Z m Z d d l m Z d d l m Z d d	 l m Z e j d
  Z d Z e j d  Z e j d d f k Z d   Z d   Z  e d d  d    Z! d   Z" d   Z# d   Z$ d   Z% d   Z& d   Z' d   Z( i d d d f d 6d d  d! f d" 6d# d$ d% f d& 6d' d( d) f d* 6d+ d, d- f d. 6d/ d0 d1 f d2 6d3 d4 d5 f d6 6d7 d8 d9 f d: 6d; d< d= f d> 6d? d@ dA f dB 6dC dD dE f dF 6dG dH dI f dJ 6dK dL dM f dN 6dO dP dQ f dR 6dS dT dU f dV 6dW dX dY f dZ 6d[ d\ d] f d^ 6d_ d` da i db d` f g dc 6f dd 6de df dg i dh df f g dc 6f di 6dj dk dl f dm 6Z) e j* dn do  Z+ dp e, f dq     YZ- dr e f ds     YZ. dt e. f du     YZ/ e j d d f k re/ Z. n  dv   Z0 d S(w   s#   variables checkers for Python code
iN(   t	   lru_cache(   t
   decorators(   t   modutils(   t   IAstroidCheckert	   INFERENCEt   INFERENCE_FAILUREt   HIGH(   t   get_global_option(   t   BaseChecker(   t   utilss   ^_{2}[a-z]+_{2}$t
   __future__s   _.*|^ignored_|^unused_i   i    c         C   sw   y |  j  |  j  } Wn t j k
 r- d SXxB | j j | g   D]+ } t | t j  rD | j t	 k rD t
 SqD Wd S(   s9   Check if the name is a future import from another module.N(   t   do_import_modulet   modnamet   astroidt   AstroidBuildingExceptiont   Nonet   localst   gett
   isinstancet
   ImportFromt   FUTUREt   True(   t   stmtt   namet   modulet
   local_node(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   _is_from_future_import<   s    c            s/   t  |  t j  o. t   f d   |  j D  S(   sE   Returns True if stmt in inside the else branch for a parent For stmt.c         3   s*   |  ]  } | j     p! |   k Vq d  S(   N(   t	   parent_of(   t   .0t	   else_stmt(   R   (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pys	   <genexpr>M   s   (   R   R   t   Fort   anyt   orelse(   t   parentR   (    (   R   s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   in_for_else_branchJ   s    t   maxsizei  c         C   sq   y t  |  j |   } Wn t t f k
 r3 d SXy | | } Wn t k
 rV d SXt | t j  rm | Sd S(   s   get overridden method if anyN(   t   nextt   local_attr_ancestorst   StopIterationt   KeyErrorR   R   R   t   FunctionDef(   t   klassR   R!   t	   meth_node(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   overridden_methodQ   s    c         C   s   d } | j    j } |  j    j | k rk |  j | j k rO d | j   } q | j r d | j } q n | j r d | j | f } n  | S(   sx   return extra information to add to the message for unpacking-non-sequence
    and unbalanced-tuple-unpacking errors
    t    s    %ss    defined at line %ss    defined at line %s of %s(   t   rootR   t   linenot	   as_string(   t   nodet   inferedt   moret   infered_module(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   _get_unpacking_extra_infob   s    		c         C   sM  d } } | r+ | j r+ | j j   } n  | rL | j rL | j j   } n  t | t j  r t |  j t j t j f  s t Sn  t d   | | f D  r t Sg  } xo | | f D]a } | } xR | rt | t j	 t j
 f  s | j |  Pn  | j r| j j   } q Pq Wq W| r=t t |   d k r=t S| j | j k  S(   s   Detect that the given frames shares a global
    scope.

    Two frames shares a global scope when neither
    of them are hidden under a function scope, as well
    as any of parent scope of them, until the root scope.
    In this case, depending from something defined later on
    will not work, because it is still undefined.

    Example:
        class A:
            # B has the same global scope as `C`, leading to a NameError.
            class B(C): ...
        class C: ...

    c         s   s+   |  ]! } t  | t j t j f  Vq d  S(   N(   R   R   t   ClassDeft   Module(   R   t   f(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pys	   <genexpr>   s   i   N(   R   R!   t   scopeR   R   R(   t	   Argumentst   FalseR   R5   R6   t   appendt   lent   setR.   (   R0   t   framet   defframet	   def_scopeR8   t   break_scopest   st   parent_scope(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   _detect_global_scopeq   s2    
					c         C   s  i  } x t  j |   D] \ } } t d   | D  r> q n  x | D] } t | t j t j f  sl qE n  x | j D]v } d } | d d k r | } n2 | d j	 d  d k s | | k r | d } n  | rv | | k rv | | | <qv qv WqE Wq Wt
 | j   d d   S(	   s    Try to fix imports with multiple dots, by returning a dictionary
    with the import names expanded. The function unflattens root imports,
    like 'xml' (when we have both 'xml.etree' and 'xml.sax'), to 'xml.etree'
    and 'xml.sax' respectively.
    c         s   s9   |  ]/ } t  | t j  o0 t  | j   t j  Vq d  S(   N(   R   R   t
   AssignNamet   assign_typet	   AugAssign(   R   R   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pys	   <genexpr>   s   i    t   *t   .it   keyc         S   s   |  d j  S(   Ni   (   t
   fromlineno(   t   a(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   <lambda>   s    N(   t   sixt	   iteritemsR   R   R   R   t   Importt   namesR   t   findt   sortedt   items(   t   not_consumedRQ   R   t   stmtsR   t   importst   second_name(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   _fix_dot_imports   s"    		%c         C   sy   | j  t j t j f  } xW | D]O } xF | j D]; \ } } | rW | |  k rm t Sq2 | r2 | |  k r2 t Sq2 Wq" Wd S(   s   
    Detect imports in the frame, with the required
    *name*. Such imports can be considered assignments.
    Returns True if an import for the given name was found.
    N(   t   nodes_of_classR   RP   R   RQ   R   R   (   R   R>   RW   t   import_nodet   import_namet   import_alias(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   _find_frame_imports   s    c         C   sG   x@ |  j  D]5 \ } } | r/ | | k r? t Sq
 | | k r
 t Sq
 Wt S(   N(   RQ   R   R:   (   R   t   global_namesR\   R]   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   _import_name_is_global   s    c         C   s&   d   |  D } t  t j j |   S(   Nc         s   s   |  ] } t  | j  Vq d  S(   N(   R=   RQ   (   R   R   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pys	   <genexpr>   s    (   R=   t	   itertoolst   chaint   from_iterable(   t   iteratort   values(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   _flattened_scope_names   s    c            s2     j    j t j  } t   f d   | D  S(   sN   
    Checks if name_node has corresponding assign statement in same scope
    c         3   s!   |  ] } | j    j  k Vq d  S(   N(   R   (   R   RL   (   t	   name_node(    s8   lib/python2.7/site-packages/pylint/checkers/variables.pys	   <genexpr>   s    (   R8   RZ   R   RE   R   (   Rg   t   assign_stmts(    (   Rg   s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   _assigned_locally   s    s#   Using variable %r before assignments   used-before-assignmentsL   Used when a local variable is accessed before it's               assignment.t   E0601s   Undefined variable %rs   undefined-variables,   Used when an undefined variable is accessed.t   E0602s%   Undefined variable name %r in __all__s   undefined-all-variables>   Used when an undefined variable name is referenced in __all__.t   E0603s7   Invalid object %r in __all__, must contain only stringss   invalid-all-objects;   Used when an invalid (non-string) object occurs in __all__.t   E0604s   No name %r in module %rs   no-name-in-modules-   Used when a name cannot be found in a module.t   E0611s0   Global variable %r undefined at the module levels   global-variable-undefineds   Used when a variable is defined through the "global" statement               but the variable is not defined in the module scope.t   W0601s-   Using global for %r but no assignment is dones   global-variable-not-assignedsx   Used when a variable is defined through the "global" statement               but no assignment to this variable is done.t   W0602s   Using the global statements   global-statements   Used when you use the "global" statement to update a global               variable. Pylint just try to discourage this               usage. That doesn't mean you cannot use it !t   W0603s.   Using the global statement at the module levels   global-at-module-levelsa   Used when you use the "global" statement at the module level               since it has no effectt   W0604s	   Unused %ss   unused-imports5   Used when an imported module or variable is not used.t   W0611s   Unused variable %rs   unused-variables-   Used when a variable is defined but not used.t   W0612s   Unused argument %rs   unused-arguments4   Used when a function or method argument is not used.t   W0613s%   Unused import %s from wildcard imports   unused-wildcard-importsk   Used when an imported module or variable is not used from a               `'from X import *'` style import.t   W0614s-   Redefining name %r from outer scope (line %s)s   redefined-outer-namesR   Used when a variable's name hides a name defined in the outer               scope.t   W0621s   Redefining built-in %rs   redefined-builtins5   Used when a variable or function override a built-in.t   W0622s/   Redefining name %r from %s in exception handlers   redefine-in-handlersW   Used when an exception handler assigns the exception                to an existing namet   W0623s)   Using possibly undefined loop variable %rs   undefined-loop-variables   Used when an loop variable (i.e. defined by a for loop or               a list comprehension or a generator expression) is used outside               the loop.t   W0631sj   Possible unbalanced tuple unpacking with sequence%s: left side has %d label(s), right side has %d value(s)s   unbalanced-tuple-unpackings>   Used when there is an unbalanced tuple unpacking in assignmentt   W0632t	   old_namest   E0632s%   Attempting to unpack a non-sequence%ss   unpacking-non-sequencesK   Used when something which is not a sequence is used in an unpack assignmentt   W0633t   E0633s    Cell variable %s defined in loops   cell-var-from-loops   A variable used in a closure is defined in a loop. This will result in all closures using the same value for the closed-over variable.t   W0640t   ScopeConsumers   to_consume consumed scope_typet   NamesConsumerc           B   sh   e  Z d  Z d   Z d   Z d   Z e d    Z e d    Z e d    Z	 d   Z
 d   Z RS(	   sZ   
    A simple class to handle consumed, to consume and scope type info of node locals
    c         C   s%   t  t j | j  i  |  |  _ d  S(   N(   R   t   copyR   t   _atomic(   t   selfR0   t
   scope_type(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   __init__]  s    c         C   s   d j  d j g  |  j j j   D] \ } } d j  | |  ^ q   } | d j  d j g  |  j j j   D] \ } } d j  | |  ^ qk   7} | d j  |  j j  7} | S(   Ns   
to_consume : {:s}
s   , s   {}->{}s   consumed : {:s}
s   scope_type : {:s}
(   t   formatt   joinR   t
   to_consumeRT   t   consumedR   (   R   RJ   t   valt   msg(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   __repr__`  s    	:		;c         C   s   t  |  j  S(   N(   t   iterR   (   R   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   __iter__j  s    c         C   s
   |  j  j S(   N(   R   R   (   R   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyR   m  s    c         C   s
   |  j  j S(   N(   R   R   (   R   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyR   q  s    c         C   s
   |  j  j S(   N(   R   R   (   R   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyR   u  s    c         C   s   | |  j  | <|  j | =d S(   sa   
        Mark the name as consumed and delete it from
        the to_consume dictionnary
        N(   R   R   (   R   R   t   new_node(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   mark_as_consumedy  s    c         C   s   | j  } | j } |  j j |  } | r~ t | t j  r~ | | d j k r~ | d j j d } | j  | k r~ d  } q~ n  | S(   Ni    (	   R   R!   R   R   R   R   t   Assignt   targetsR   (   R   R0   R   t   parent_nodet
   found_nodet   lhs(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   get_next_to_consume  s    		(   t   __name__t
   __module__t   __doc__R   R   R   t   propertyR   R   R   R   R   (    (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyR   Y  s   		
		t   VariablesCheckerc           B   s  e  Z d  Z e Z d Z e Z d Z d i d d 6d d 6d d	 6d
 d 6f d i d d 6d d 6d d	 6d d 6f d i d^ d 6d d 6d d	 6d d 6f d i d_ d 6d d 6d d	 6d d 6f d i d` d 6d d 6d d	 6d  d 6f d! i e	 d 6d d 6d d	 6d" d 6f d# i e
 d 6d d 6d d	 6d$ d 6f f Z da d%  Z e j d&    Z e j d'    Z e j d(    Z e j d)  d*    Z e j d)  d+    Z d,   Z e j d- d. d/ d0 d1 d2  d3    Z d4   Z d5   Z d6   Z d7   Z d8   Z d9   Z d:   Z d;   Z  d<   Z! d=   Z" d>   Z# d?   Z$ d@   Z% dA   Z& dB   Z' dC   Z( dD   Z) e& Z* e) Z+ e j dE dF dG dH d/  dI    Z, dJ   Z- dK   Z. dL   Z/ e j dM  dN    Z0 dO   Z1 dP   Z2 e3 dQ    Z4 e3 dR    Z5 dS   Z6 e j e j7     dT    Z8 dU   Z9 e j dV  dW    Z: e j dV  dX    Z; e j dY dZ  d[    Z< d\   Z= d]   Z> RS(b   s   checks for
    * unused variables / imports
    * undefined variables
    * redefinition of variable from builtins or from an outer scope
    * use of variable before assignment
    * __all__ consistency
    t	   variablesis   init-importi    t   defaultt   ynt   types   <y_or_n>t   metavarsB   Tells whether we should check for unused import in __init__ files.t   helps   dummy-variables-rgxs;   _+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_t   regexps   <regexp>sU   A regular expression matching the name of dummy variables (i.e. expectedly not used).s   additional-builtinst   csvs   <comma separated list>s   List of additional names supposed to be defined in builtins. Remember that you should avoid to define new builtins when possible.t	   callbackst   cb_t   _cbs   <callbacks>s|   List of strings which can identify a callback function by name. A callback name must start or end with one of those strings.s   redefining-builtins-moduless	   six.movess   past.builtinss   future.builtinst   iot   builtinssQ   List of qualified module names which can have objects that can redefine builtins.s   ignored-argument-namessb   Argument names that match this expression will be ignored. Default to name with leading underscores   allow-global-unused-variablessG   Tells whether unused global variables should be treated as a violation.c         C   s/   t  j |  |  d  |  _ d  |  _ g  |  _ d  S(   N(   R   R   R   t   _to_consumet   _checking_mod_attrt   _loop_variables(   R   t   linter(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyR     s    		c         C   s   t  |  d d t S(   Ns   analyse-fallback-blocksR   (   R   R:   (   R   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   _analyse_fallback_blocks  s    c         C   s   t  |  d d g  S(   Ns   ignored-modulesR   (   R   (   R   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   _ignored_modules  s    c         C   s   t  |  d d t S(   Ns   allow-global-unused-variablesR   (   R   R   (   R   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   _allow_global_unused_variables  s    s   redefined-outer-namec         C   s   g  | j  j t j  D] } | j ^ q } |  j j } g  | D] } | j |  s> | ^ q> } xj | D]b } xY |  j D]N \ } } | | k rv t	 | |  rv |  j
 d d | | j f d | Pqv qv Wqf W|  j j | | f  d  S(   Ns   redefined-outer-namet   argsR0   (   t   targetRZ   R   RE   R   t   configt   dummy_variables_rgxt   matchR   R"   t   add_messageRK   R;   (   R   R0   t   vart   assigned_tot	   dummy_rgxt   variablet	   outer_fort   outer_variables(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt	   visit_for  s    +(c         C   s   |  j  j   d  S(   N(   R   t   pop(   R   t   _(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt	   leave_for  s    c         C   s   t  | d  g |  _ x t j | j  D]t \ } } t j |  r( t j | d  r( |  j | d  s( | d k r| q( n  |  j	 d d | d | d q( q( Wd S(   sn   visit module : update consumption analysis variable
        checks globals doesn't overrides builtins
        R   i    R   s   redefined-builtinR   R0   N(
   R   R   RN   RO   R   R	   t
   is_builtint   is_inside_exceptt    _should_ignore_redefined_builtinR   (   R   R0   R   RV   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   visit_module  s    #s   unused-imports   unused-wildcard-imports   redefined-builtins   undefined-all-variables   invalid-all-objects   unused-variablec         C   s   t  |  j  d k s t  |  j j   j } d | j k rO |  j | |  n  |  j |  |  j j	 rv | j
 rv d S|  j |  d S(   s$   leave module: check globals
        i   t   __all__N(   R<   R   t   AssertionErrorR   R   R   t
   _check_allt   _check_globalsR   t   init_importt   packaget   _check_imports(   R   R0   RU   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   leave_module  s    c         C   s  t  | j d   } | t j k r( d  Sxt | d d
  D]} y t  | j    } Wn t j k
 rp q; n X| t j k r q; n  | j s q; n  t	 | t j
  s t	 | j t j  r |  j d d | j   d | q; n  | j } | | k r| | =q; n  | | j k r; | j s<|  j d d | f d | qt j j | j  d } t j j |  d k r| j d	 | } y t j | j d	   Wqt k
 r|  j d d | f d | qt k
 rqXqq; q; Wd  S(   NR   t   eltss   invalid-all-objectR   R0   s   undefined-all-variablei    R   RI   (    (   R$   t   igetattrR   t   YESt   getattrt   infert   InferenceErrort   UninferableR!   R   t   Constt   valueRN   t   string_typesR   R/   R   R   t   ost   patht   splitextt   filet   basenameR   R   t   file_from_modpatht   splitt   ImportErrort   SyntaxError(   R   R0   RU   t   assignedt   eltt   elt_nameR   R   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyR     sJ    				
	
c         C   s^   |  j  r d  SxJ t j |  D]9 \ } } x* | D]" } |  j d d | f d | q0 Wq Wd  S(   Ns   unused-variableR   R0   (   R   RN   RO   R   (   R   RU   R   t   nodesR0   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyR   C  s
    	c         C   s'  t  |  } t   } x| D]\ } } x| j D]} | d } } | d k r[ | } n  | d }	 | | k rw q2 n  | | |	 f k r q2 n  | j |  t | t j  s t | t j  rH| j rHt | t j  r t	 j
 |  r q2 n  |	 d k rq2 n  |	 d  k rd | }
 n d | |	 f }
 |  j d d |
 d	 | q2 t | t j  r2 | j t k r2 t	 j
 |  r~q2 n  t | |  rq2 n  | d k r|  j d
 d | d	 | q|	 d  k rd | | j f }
 n | | j |	 f } d | }
 |  j d d |
 d	 | q2 q2 Wq W|  ` d  S(   Ni    RH   i   R   s	   import %ss   %s imported as %ss   unused-importR   R0   s   unused-wildcard-imports   %s imported from %ss   %s imported from %s as %s(   RY   R=   RQ   t   addR   R   RP   R   R   t   SPECIAL_OBJt   searchR   R   R   R   R   (   R   RU   t   local_namest   checkedR   R   RW   t	   real_namet   imported_namet   as_nameR   t   fields(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyR   J  sP    		


$c         C   s   |  j  j t | d   d S(   s:   visit class: update consumption analysis variable
        t   classN(   R   R;   R   (   R   R0   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   visit_classdef  s    c         C   s   |  j  j   d S(   s:   leave class: update consumption analysis variable
        N(   R   R   (   R   R   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   leave_classdef  s    c         C   s   |  j  j t | d   d S(   s;   visit lambda: update consumption analysis variable
        t   lambdaN(   R   R;   R   (   R   R0   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   visit_lambda  s    c         C   s   |  j  j   d S(   s;   leave lambda: update consumption analysis variable
        N(   R   R   (   R   R   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   leave_lambda  s    c         C   s   |  j  j t | d   d S(   s<   visit genexpr: update consumption analysis variable
        t   comprehensionN(   R   R;   R   (   R   R0   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   visit_generatorexp  s    c         C   s   |  j  j   d S(   s<   leave genexpr: update consumption analysis variable
        N(   R   R   (   R   R   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   leave_generatorexp  s    c         C   s   |  j  j t | d   d S(   s=   visit dictcomp: update consumption analysis variable
        R   N(   R   R;   R   (   R   R0   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   visit_dictcomp  s    c         C   s   |  j  j   d S(   s=   leave dictcomp: update consumption analysis variable
        N(   R   R   (   R   R   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   leave_dictcomp  s    c         C   s   |  j  j t | d   d S(   s<   visit setcomp: update consumption analysis variable
        R   N(   R   R;   R   (   R   R0   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   visit_setcomp  s    c         C   s   |  j  j   d S(   s<   leave setcomp: update consumption analysis variable
        N(   R   R   (   R   R   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   leave_setcomp  s    c         C   sU  |  j  j t | d   |  j j d  p: |  j j d  sA d S| j   j } x | j   D] \ } } t j	 |  r~ q] n  | | k rt
 | t j  r| | d } t
 | t j  r | j t k r q] n  | j } |  j | |  sM|  j d d | | f d | qMq] t j |  r] |  j |  r] |  j d d | d | q] q] Wd S(   sN   visit function: update consumption analysis variable and check locals
        t   functions   redefined-outer-names   redefined-builtinNi    R   R0   (   R   R;   R   R   t   is_message_enabledR-   t   globalsRT   R	   R   R   R   t   GlobalR   R   R   RK   t   _is_name_ignoredR   R   R   (   R   R0   t   globsR   R   t
   definitiont   line(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   visit_functiondef  s&    	c         C   s[   |  j  j } t | t j  rB t | j t j  rB |  j  j } n | } | oZ | j |  S(   N(	   R   R   R   R   RE   R!   R9   t   ignored_argument_namesR   (   R   R   R   t   authorized_rgxt   regex(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyR     s    c            s  |  j  | |  r d  St   t j  rn | d k rn t   j d  d k rn t   j d d t j  rn d  St | t j  r d  St | t j t j	 f  r | r t
 | |  r d  Sn  t t j   j   g    j j D] } | j ^ q   }   j   }   j j   }	 | rFt |	 t j  rFt j |	  r=t n t }
 n t }
 | | k r8| r  j d k r| | d k rd  St |	   j  } | d  k	 r| | j   k rd  S  j t j k r  j d k rd  Sn  t   f d   |  j j  D  rd  St j!    rd  S|  j" d d	 | d
 | d |
 n~ | j rit | j t j#  ri| | k rid  Sn  t | t j  r| j$ d \ } } | p| } n  |  j" d d	 | d
 | d  S(   Nt	   __class__i   i    t   staticmethodR   t   __new__c         3   s3   |  ]) }   j  j |  p*   j  j |  Vq d  S(   N(   R   t
   startswitht   endswith(   R   t   cb(   R0   (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pys	   <genexpr>  s   s   unused-argumentR   R0   t
   confidences   unused-variable(   R   R	  (%   R   R   R   R(   R<   R   R5   R   RP   R   R`   t   listRa   Rb   t   argnamesR   t
   kwonlyargsR   t	   is_methodR!   R>   R	   t   has_known_basesR   R   R   R   R+   R   t	   PYMETHODSR   R   R   t(   is_registered_in_singledispatch_functionR   R   RQ   (   R   R   R0   R   R_   t   nonlocal_namest   argR  R  R)   R  t
   overriddent   qnamet   asname(    (   R0   s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   _check_is_unused  sV    		(!
c         C   s   |  j  j   j } |  j j d  p3 |  j j d  s: d St j |  rM d S| j   } | ro | j   ro d St	 | j
 t j   } t	 | j
 t j   } x: t j |  D]) \ } } |  j | | | d | |  q Wd S(   s4   leave function: check function's locals are consumeds   unused-variables   unused-argumentNi    (   R   R   R   R   R   R	   t   is_errorR  t   is_abstractRf   RZ   R   R   t   NonlocalRN   RO   R  (   R   R0   RU   R  R_   R  R   RV   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   leave_functiondef  s    s   global-variable-undefineds   global-variable-not-assigneds   global-statements   global-at-module-levelc         C   s]  | j    } t | t j  r5 |  j d d | d S| j   } t } x | j D] } y | j |  } Wn t j	 k
 r g  } n X| s |  j d d | d | t
 } qQ n  x | D]] } t | t j  r | j | j k r |  j d d | d | Pn  | j    | k r Pq q W|  j d d | d | t
 } qQ W| rY|  j d d | n  d S(	   s/   check names imported exists in the global scopes   global-at-module-levelR0   Ns   global-variable-not-assignedR   s   redefined-builtins   global-variable-undefineds   global-statement(   R>   R   R   R6   R   R-   R   RQ   R   t   NotFoundErrorR:   RE   R   t   special_attributes(   R   R0   R>   R   t   default_messageR   t   assign_nodest   anode(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   visit_global4  s6    

c            s8    f d   } | j      t   t j t j f  s: d  St | j t j  rS d  St | t j  r | j j | j     r4|  j	 d d | d | j
 q4n | j    } | } x t | t j  s | | k r Pn  | j } q W| j    r4|   r4t   j   t j  r4|  j	 d d | d | j
 n  d  S(   Nc              s%   t    j t j  o$   j j   k S(   N(   R   R!   R   t   Callt   func(    (   t
   node_scope(    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   _is_direct_lambda_call^  s    s   cell-var-from-loopR0   R   (   R8   R   R   t   LambdaR(   R!   R9   t   ComprehensionR   R   R   R   t	   statementt   Return(   R   R0   t   assignment_nodeR(  t   assign_scopet	   maybe_for(    (   R'  s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   _check_late_binding_closure]  s&    "
c         C   s  |  j  j d  s d  Sg  | j |  d D] } t | d  r* | ^ q* } | s | d j sl | d j r | d j   j |  r g  } n
 | d  } xd t | d  D]R \ } } | | j   j |  r t	 | | j   |  r q n  | j
 |  q W| } t |  d k r| d j   } t | t j t j t j f  r| j   | j   k	 r|  j d d | d | qn  d  S(   Ns   undefined-loop-variablei   t   ass_typei    R   R0   (   R   R   t   lookupt   hasattrt   is_statementR!   R+  R   t	   enumerateR"   R;   R<   RF   R   R   R   R*  t   GeneratorExpR   (   R   R0   R   R   t   astmtst   _astmtst   it   assign(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   _loopvar_namex  s(    !	
c         C   s)   t  | t j  s t S| j |  j j k S(   N(   R   R   R   R:   R   R   t   redefining_builtins_modules(   R   R   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyR     s    s   redefine-in-handlerc         C   sX   xQ t  j | j  D]= } t  j |  \ } } | r |  j d d | d | q q Wd  S(   Ns   redefine-in-handlerR   R0   (   R	   t   get_all_elementsR   t   clobber_in_exceptR   (   R   R0   R   t
   clobberingR   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   visit_excepthandler  s    c         C   s,   t  | j   t j  r( |  j |  n  d  S(   N(   R   RF   R   RG   t
   visit_name(   R   R0   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   visit_assignname  s    c         C   s   |  j  |  d  S(   N(   RA  (   R   R0   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   visit_delname  s    c         C   s   t  } t | t j  r |  j   | k r t rx |  | j j k p |  | j j k p |  | j j	 k p |  | j j
 k p | j j |   } n  | S(   N(   R:   R   R   R(   R+  t   PY3KR   t   annotationst   kwonlyargs_annotationst   varargannotationt   kwargannotationR   (   R0   R>   t   in_annotation_or_default(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   _defined_in_function_definition  s    c	            s  t  }	 t }
 t } | | k	 r3 t |  | |  }	 n | j d  k rp   | j k sd t j    d r&t }	 q&n t | t j	  s t |  j
   t j  o t |   } | r | j   j    d r t }	 | | k o t | t j j  } n5   | j k r&t   f d   | j   D  }	 n  | d k rt | t j  r  | j k rt | t j  o|  | j k o| j   d j | j k  }	 nGt | t j  rXt | t j	  rXt r|  | j k r| j | j  rt  }	 }
 n  |	 r+| j | j k r+| j   d j | j k  r+t }	 n  t |  j t j  r| j | j k }	 qn | rgt  }	 nu |	 o|| j | j k }	 |	 r| j | j k rt | t j	  r| | k r| j |   r| | k	 rt }	 qn  |	 |
 | f S(   Ni   c         3   s0   |  ]& } t  | t j  o'   | j k Vq d  S(   N(   R   R   R  RQ   (   R   t   child(   R   (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pys	   <genexpr>  s   R   i    (   R   R:   RD   R!   R   t   scope_attrsR   t   builtin_lookupR   R(   R>   R)  Ri   R-   R2  t   node_classesR*  R   R   t   get_childrenR5   R9   t   defaultsRK   RD  t   returnsR   R   R.   (   R0   R   t   defnodeR   t   defstmtR>   R?   t   base_scope_typet   recursive_klasst
   maybee0601t   annotation_returnt   use_outer_definitiont   forbid_lookup(    (   R   s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   _is_variable_violation  sX    " !		c         C   st   | j  } | j   j   } |  j | |  } | rH | j j   j } n	 | j } t | t j  si | or | | k S(   s  
        Return True if the node is in a local class scope, as an assignment.

        :param node: Node considered
        :type node: astroid.Node
        :return: True if the node is in a local class scope, as an assignment. False otherwise.
        :rtype: bool
        (	   R   R+  R8   RJ  R!   R   R   R   R5   (   R   R0   R   R>   RI  t   frame_locals(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   _ignore_class_scope  s    		c         C   s  | j    } | j d k r> | j   j j d  s: t  d S| j } | j   } t	 j
 |  rr t	 j |  s t	 j |  s t	 j | |  r t |  j  d } n t |  j  d } |  j | j } xt | d d  D]p} |  j | } | j d k rB| | k rB| d k o&| | d k rB|  j |  rBq qBn  | | j k r| j d k oo|  j | |  rt	 j | j | d  }	 |  j | |	  |  j | |  Pn  | j |  }
 |
 d k rq n  t	 j | j | d  }	 |	 d k	 r.|  j | |	  |	 j    } | j   } | | k o\| j |  o\t | t j  o\| j | j k } |  j | | |	 | | | | | | 	 \ } } } | rq n  | r.t	 j  |  r.t j! | | d  r.| | k ot | t j" t j# f  } | s| s| st | t j$  rCt	 j% | t&  s(|  j' d
 d | d | q(q+| d k rk|  j' d d | d | q+| d k r+t | t j  r| | j( k rt | j) t j*  r| j | j k r|  j' d d | d | qq%|  j' d
 d | d | q(| j d k r(|  j' d
 d | d | q(q+q.n  | j+ | |
  |  j | |  Pq W| t j, j- k pt	 j. |  p| |  j/ j0 k st	 j% | t&  s|  j' d
 d | d | qn  d S(   sb   check that a name is defined if the current scope and doesn't
        redefine a built-in
        s   .pyNi   i   iR   R   i    t	   NameErrors   undefined-variableR   R0   R   s   used-before-assignment(   R]  (1   R+  RK   R   R-   R   R  R   R   R8   R	   t   is_func_defaultt   in_comprehensiont   is_func_decoratort   is_ancestor_nameR<   R   R   t   rangeR\  R   t$   _has_homonym_in_upper_function_scopet   assign_parentR0  R;  R   R   R>   R   R   R   R5   RZ  t   is_defined_beforet   are_exclusivet   DelNameRE   t   Deletet   node_ignores_exceptionR]  R   R   R!   R9   R   R6   RL  R   R   t   additional_builtins(   R   R0   R   R   R>   t   start_indexRT  R9  t   current_consumerRR  R   RS  R?   RU  RV  RW  RX  t   defined_by_stmt(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyRA  ?  s    	!	!!c         C   sN   xG |  j  | d d d  D]+ } | j d k r | j | j k r t Sq Wt S(   s  
        Return True if there is a node with the same name in the to_consume dict of an upper scope
        and if that scope is a function

        :param node: node to check for
        :type node: astroid.Node
        :param index: index of the current consumer inside self._to_consume
        :type index: int
        :return: True if there is a node with the same name in the to_consume dict of a upper scope
                 and if that scope is a function
        :rtype: bool
        i   NiR   (   R   R   R   R   R   R:   (   R   R0   t   indext	   _consumer(    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyRc    s    !!s   no-name-in-modulec         C   s   |  j  r t j |  r d Sxt | j D]i \ } } | j d  } y t | j | d   } Wn t j k
 rx q' n X|  j	 | | | d  q' Wd S(   s    check modules attribute accessesNRI   i    i   (
   R   R	   t   is_from_fallback_blockRQ   R   R$   t   infer_name_moduleR   t   ResolveErrort   _check_module_attrs(   R   R0   R   R   t   partsR   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   visit_import  s    c         C   s   |  j  r t j |  r d S| j j d  } y | j | d  } Wn t j k
 r] d SX|  j | | | d  } | s d SxE | j	 D]: \ } } | d k r q n  |  j | | | j d   q Wd S(   s    check modules attribute accessesNRI   i    i   RH   (
   R   R	   Rp  R   R   R   R   R   Rs  RQ   (   R   R0   t
   name_partsR   R   R   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   visit_importfrom  s    s   unbalanced-tuple-unpackings   unpacking-non-sequencec         C   s   t  | j d t j t j f  s& d S| j d j   } y8 t j | j  } | d k	 rp |  j
 | | |  n  Wn t j k
 r d SXd S(   s^   Check unbalanced tuple unpacking for assignments
        and unpacking non-sequences.
        i    N(   R   R   R   t   Tuplet   Listt   iteredR	   t
   safe_inferR   R   t   _check_unpackingR   (   R   R0   R   R1   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   visit_assign  s    "c      	   C   sP  t  j |  r d St  j |  r& d S| t j k r9 d St | j t j  r t | j t j	  r | j j
 | j j k r d St | t j t j f  r| j   } t |  t |  k rLt d   | D  r d S|  j d d | d t | |  t |  t |  f qLn7 t  j |  sL|  j d d | d t | |  f n  d S(   sS    Check for unbalanced tuple unpacking
        and unpacking non sequences.
        Nc         s   s!   |  ] } t  | t j  Vq d  S(   N(   R   R   t   Starred(   R   R   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pys	   <genexpr>  s   s   unbalanced-tuple-unpackingR0   R   s   unpacking-non-sequence(   R	   t   is_inside_abstract_classt   is_comprehensionR   R   R   R!   R9   R   t   NameR   t   varargRx  Ry  Rz  R<   R   R   R4   t   is_iterable(   R   R1   R0   R   Re   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyR|    s.    		c         C   sK  t  | t j  s t |   x | r | j d  } | d k rL d } Pn  y6 t | j |  d j    } | t j	 k r d SWq! t j
 k
 r | j |  j k r d S|  j d d | | j f d | d St j k
 r d SXq! W| r1| r | j n d } |  j d d | d d j |  | f d St  | t j  rG| Sd S(   s   check that module_names (list of string) are accessible through the
        given module
        if the latest access name corresponds to a module, return it
        i    t   __dict__s   no-name-in-moduleR   R0   RI   N(   R   R   R6   R   R   R   R$   R   R   R   R  R   R   R   R   R   (   R   R0   R   t   module_namesR   R   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyRs  )  s4    		(    (   R   R   (   s	   six.movess   past.builtinss   future.builtinsR   R   N(?   R   R   R   R   t   __implements__R   t   MSGSt   msgst   priorityt   IGNORED_ARGUMENT_NAMESR   t   optionsR   R   R   t   cachedpropertyR   R   R   R	   t   check_messagesR   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R  R   R  R  t   visit_asyncfunctiondeft   leave_asyncfunctiondefR$  R0  R;  R   R@  RB  RC  R  RJ  RZ  R\  t   keysRA  Rc  Ru  Rw  R}  R|  Rs  (    (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyR     s   









		0		7														@	'		%			[	#		"t   VariablesChecker3kc           B   sD   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s!   Modified variables checker for 3kc         C   s   |  j  j t | d   d S(   s=   visit dictcomp: update consumption analysis variable
        R   N(   R   R;   R   (   R   R0   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   visit_listcompP  s    c         C   s   |  j  j   d S(   s=   leave dictcomp: update consumption analysis variable
        N(   R   R   (   R   R   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   leave_listcompU  s    c         C   s'   |  j  |  t t |   j |  d  S(   N(   t   _check_metaclassest   superR  R  (   R   R0   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyR  [  s    c         C   s'   |  j  |  t t |   j |  d  S(   N(   R  R  R  R   (   R   R0   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyR   _  s    c         C   sv   g  } xB | j    D]4 } t | t j  r | j |  j | |   q q Wx$ | D] \ } } | j | d  qR Wd S(   s.    Update consumption analysis for metaclasses. N(   RO  R   R   R5   t   extendt   _check_classdef_metaclassesR   R   (   R   R0   R   t
   child_nodet   scope_localsR   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyR  c  s     c   	      C   s  | j  s g  Sg  } | j   } d  } t | j  t j  rI | j  j } n | ra | j   j } n  d  } | r xV |  j d  d  d  D]; \ } } } | j	 |  } | r | j
 | | f  Pq q Wn  | d  k r| rd  } t | j  t j  r| j  j } n' t | j  t j  r*| j  j   } n  | d  k	 r| t j j k put j |  pu| |  j j k pu| | j k s|  j d d | d | f qqn  | S(   Nis   undefined-variableR0   R   (   t
   _metaclasst	   metaclassR   R   R   R  R   R-   R   R   R;   t	   AttributeR/   R6   RL  R	   R   R   Rj  R   R   (	   R   R)   R   R   R  R   t   foundR  R   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyR  p  s>    	&(	   R   R   R   R  R  R  R   R  R  (    (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyR  L  s   					c         C   s   |  j  t |    d S(   s-   required method to auto register this checkerN(   t   register_checkerR   (   R   (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   register  s    (1   R   R   Ra   t   collectionsR   t   syst   ret	   functoolsR    R   t   backports.functools_lru_cacheRN   R   R   R   t   pylint.interfacesR   R   R   R   t   pylint.utilsR   t   pylint.checkersR   R	   t   compileR   R   R  t   version_infoRD  R   R"   R+   R4   RD   RY   R^   R`   Rf   Ri   R  t
   namedtupleR   t   objectR   R   R  R  (    (    (    s8   lib/python2.7/site-packages/pylint/checkers/variables.pyt   <module>   s   "				@	 				
















5   N	