
'![c           @   sS  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z d d l m Z m	 Z	 d d l
 m Z m Z d d l m Z d d l m Z d d l m Z d d	 l m Z d d
 l m Z d d l m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m  Z  m! Z! m" Z" m# Z# m$ Z$ m% Z% d d l& m' Z' e j( d d f k rZd Z) n d Z) d d d d h Z* e j+ d d  Z, e j+ d d  Z- d   Z. d   Z/ d   Z0 d   Z1 d   Z2 d   Z3 d   Z4 d    Z5 d!   Z6 d"   Z7 d#   Z8 d$   Z9 d%   Z: d&   Z; e< d'  Z= d(   Z> i d) d* d+ f d, 6d- d. d/ f d0 6d1 d2 d3 f d4 6d5 d6 d7 f d8 6d9 d: d; f d< 6d= d> d? f d@ 6dA dB dC f dD 6dE dF dG f dH 6dI dJ dK f dL 6dM dN dO f dP 6dQ dR dS f dT 6dU dV dW f dX 6dY dZ d[ f d\ 6d] d^ d_ f d` 6da db dc f dd 6de df dg f dh 6di dj dk f dl 6dm dn do f dp 6dq dr ds f dt 6du dv dw f dx 6dy dz d{ f d| 6d} 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 d d f d 6d d d f d 6Z? d e@ f d     YZA d e f d     YZB d e f d     YZC d d  ZD d   ZE d   ZF d S(   s    classes checker for Python code
i(   t
   generatorsN(   t	   Generatort   BUILTINS(   t   InconsistentMroErrort   DuplicateBasesError(   t
   decorators(   t   objects(   t   function_to_method(   t   IAstroidChecker(   t   BaseChecker(   t	   PYMETHODSt   SPECIAL_METHODS_PARAMSt   overrides_a_methodt   check_messagest   is_attr_privatet   is_attr_protectedt   node_frame_classt   is_builtin_objectt   decorated_with_propertyt   unimplemented_abstract_methodst   decorated_witht   class_is_abstractt
   safe_infert   has_known_basest   is_iterablet   is_comprehension(   t   get_global_optioni   i    t   __next__t   nextt   boolt   ranget   slicet
   memoryviewt   _CallSignatures!   args kws starred_args starred_kwst   _ParameterSignatures   args kwonlyargs varargs kwargsc         C   s8  i  } g  } g  } g  } x |  j  p' g  D]v } | j | j } } | d  k rr t | t j  rr | j | j  q( t | t j  r | j | | <q( d  | | <q( Wx |  j	 D]u } t | t j
  r t | j t j  r | j | j j  q t | t j  r| j | j  q | j d   q Wt | | | |  S(   N(   t   keywordst   argt   valuet   Nonet
   isinstancet   astroidt   Namet   appendt   namet   argst   StarredR!   (   t   callt   kwsR,   t   starred_kwst   starred_argst   keywordR$   R%   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   _signature_from_callE   s$    'c         C   sr   |  j  } |  j } g  |  j D] } | j d k r | j ^ q } g  |  j D] } | j ^ qJ } t | | | |  S(   Nt   self(   t   kwargt   varargR,   R+   t
   kwonlyargsR"   (   t	   argumentsR5   R6   R$   R,   R7   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   _signature_from_argumentsb   s
    		.c   
         s   |  j  r |  j    j k } n
   j } |  j rF |  j   j k } n
   j } t   f d   |  j D  } |  j   j k } t }   j r xJ   j D]< } |   j k } | |  j k }	 | r |	 r t	 } Pq q Wn  t | | | | | f  S(   s8   Check if a definition signature is equivalent to a call.c         3   s   |  ] } |   j  k Vq d  S(   N(   R/   (   t   .0t   kw(   R.   (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pys	   <genexpr>t   s    (
   t   kwargsR0   t   varargsR1   t   allR7   R,   t   TrueR/   t   False(
   t
   definitionR.   t   same_kw_variadicst   same_args_variadicst   same_kwonlyargst	   same_argst   no_additional_kwarg_argumentsR2   t   is_argt	   is_kwonly(    (   R.   s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   _definition_equivalent_to_callj   s,    	
	
	c         C   s,   |  j  j  } |  j d k r( | d } n  | S(   Nt   classmethodt   methodi   (   RJ   RK   (   R,   t   type(   RK   t
   positional(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   _positional_parameters   s    c         C   s(   x! | D] } t  |  |  r | Sq Wd S(   s   
    Return the type of the node if it exists in potential_types.

    Args:
        node (astroid.node): node to get the type of.
        potential_types (tuple): potential types of the node.

    Returns:
        type: type of the node or None.
    N(   R'   R&   (   t   nodet   potential_typest   potential_type(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   _get_node_type   s    c         C   s   t  |  |  t  | |  k S(   s}  
    Check equality of nodes based on the comparison of their attributes named attr_name.

    Args:
        node_a (astroid.node): first node to compare.
        node_b (astroid.node): second node to compare.
        attr_name (str): name of the nodes attribute to use for comparison.

    Returns:
        bool: True if node_a.attr_name == node_b.attr_name, False otherwise.
    (   t   getattr(   t   node_at   node_bt	   attr_name(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   _check_arg_equality   s    c         C   s  |  j  d k s | j  d k r" t Sg  |  j  D] } | j ^ q, } t   } x?| D]7} y |  j |  } Wn t j j k
 r | } n Xy | j |  } Wn t j j k
 r | } n Xg  | | f D] } | | k ^ q }	 t	 |	  r t
 |	  r t Si d t j 6d t j 6d t j 6d t j 6}
 t d   |
 D  } t | |  } | rQ t | |  skt St | | |
 |  st SqQ qQ Wt S(   s0  
    Check if original and overridden methods arguments have different default values

    Return True if one of the overridden arguments has a default
    value different from the default value of the original argument
    If one of the method doesn't have argument (.args is None)
    return False
    R%   R+   t   eltsc         s   s   |  ] } | Vq d  S(   N(    (   R:   t   astroid_type(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pys	   <genexpr>   s    N(   R,   R&   R@   R+   t   objectt   default_valueR(   t
   exceptionst	   NoDefaultt   anyR>   R?   t   Constt   ClassDeft   Tuplet   Listt   tupleRR   R'   RW   (   t   originalt
   overriddent   paramt   original_param_namest   default_missingt
   param_namet   original_defaultt   overridden_defaultR$   t   default_listt   astroid_type_compared_attrt   handled_typest   original_type(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt'   _has_different_parameters_default_value   s6    		

%	c   	      C   s   t  j j |  |  } x | D]x \ } } | | f } t |  sD t Sg  | D] } | j ^ qK } t t | j |   r~ q n  | j | j k r t Sq Wt	 S(   N(
   t   sixt   movest   zip_longestR>   R?   R+   R^   t   mapt   matchR@   (	   Rd   Re   t   dummy_parameter_regext   zippedt   original_paramt   overridden_paramt   paramsRf   t   names(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   _has_different_parameters   s    c   	      C   s   t  |   } t  |  } t | | |  } t |  j j | j j |  } |  j t k rd t } } n  t d   |  j j | j j f D  d k } t d   |  j j	 | j j	 f D  d k } t
 | | | | f  S(   sE  Determine if the two methods have different parameters

    They are considered to have different parameters if:

       * they have different positional parameters, including different names

       * one of the methods is having variadics, while the other is not

       * they have different keyword only parameters.

    c         s   s   |  ] } | s d  Vq d S(   i   N(    (   R:   Rf   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pys	   <genexpr>  s    i   c         s   s   |  ] } | s d  Vq d S(   i   N(    (   R:   Rf   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pys	   <genexpr>  s    (   RN   R|   R,   R7   R+   R
   R@   t   sumR5   R6   R^   (	   Rd   Re   Rv   t   original_parameterst   overridden_parameterst   different_positionalt   different_kwonlyt   different_kwargt   different_vararg(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   _different_parameters   s.    				"	"	c         C   s   |  j  t k o t |   S(   N(   R+   t   INVALID_BASE_CLASSESR   (   t   cls(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   _is_invalid_base_class!  s    c         C   s   |  j  |  } x | D] } yl xe | j   D]W } t | t j  r, y | j  d  | j  d  Wn t j k
 r{ q, q Xt Sq, q, WWq t j k
 r t SXq Wt S(   Nt   __get__t   __set__(	   RS   t   inferR'   R(   t   Instancet   NotFoundErrorR?   t   InferenceErrorR@   (   R   t   attrt
   attributest	   attributet   inferred(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   _has_data_descriptor%  s    	c   	   	   C   s  t  |  t j  s t Sx | D] } y | j |  } Wn t j k
 rO q n Xx | D] } x | j t j  D] } y t | j	 j
    } Wn t j t f k
 r qp n Xt  | t j  s qp n  | j } t  | t j  r | j } n  | j |  j k rp t Sqp WqW Wq Wt S(   s    Check if the func was called in any of the given methods,
    belonging to the *klass*. Returns True if so, False otherwise.
    (   R'   R(   t   FunctionDefR@   RS   R   t   nodes_of_classt   CallR   t   funcR   R   t   StopIterationt   BoundMethodt   _proxiedt   UnboundMethodR+   R?   (	   R   t   klasst   methodsRK   t   inferedt   infer_methodR.   t   boundt   func_obj(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   _called_in_methods8  s*    	c         C   s   y | j  |   } Wn t j k
 r* t SXd j t  } xv | D]n } y t | j    } Wn t j k
 rv qA n Xt	 | t j
  r t |  r t S| j   | k rA t SqA Wt S(   s4   Check if the given attribute *name* is a property
    in the given *klass*.

    It will look for `property` calls or for functions
    with the given name, decorated by `property` or `property`
    subclasses.
    Returns ``True`` if the name is a property in the given klass,
    ``False`` otherwise.
    s   {0}.property(   RS   R(   R   R@   t   formatR   R   R   R   R'   R   R   R?   t   pytype(   R+   R   R   t   property_nameR   R   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   _is_attribute_propertyS  s     c         C   sY   xR |  j  t j  D]> } | j } t | t j  r | j d k r | j r t Sq Wt	 S(   Nt   super(
   R   R(   R   R   R'   R)   R+   R,   R?   R@   (   t   fundef_nodeR.   R   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   _has_bare_super_callp  s    	
c         C   s   y% |  j  | d | } t |  } Wn& t j k
 r< d St k
 rM d SXy t |  d SWn& t j k
 rw d St k
 r | SXd S(   s   
    Safely infer the return value of a function.

    Returns None if inference failed or if there is some ambiguity (more than
    one node has been inferred). Otherwise returns infered value.
    t   contextN(   t   infer_call_resultR   R(   R   R&   R   (   RO   t   callerR   t   inferitR%   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   _safe_infer_call_resultz  s    
c         C   s`   t  | j    } t | t j  r\ | j   } t d   t j j	 |  |  D  r\ t
 Sn  t S(   Nc         s   s3   |  ]) \ } } | o* | o* | j  | j  k Vq d  S(   N(   R%   (   R:   t
   first_slott   second_slot(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pys	   <genexpr>  s   (   R   R   R'   R(   R`   t   slotsR>   Rq   Rr   Rs   R?   R@   (   R   t   assigned_valueR   t   other_slots(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   _has_same_layout_slots  s    	s+   Unable to check methods signature (%s / %s)s   method-check-faileds   Used when Pylint has been unable to check methods signature compatibility for an unexpected reason. Please report this kind if you don't make sense of it.t   F0202s4   An attribute defined in %s line %s hides this methods   method-hiddens~   Used when a class defines a method which is hidden by an instance attribute from an ancestor class or set by some client code.t   E0202s1   Access to member %r before its definition line %ss   access-member-before-definitionsG   Used when an instance member is accessed before it's actually assigned.t   E0203s%   Attribute %r defined outside __init__s   attribute-defined-outside-initsG   Used when an instance attribute is defined outside the __init__ method.t   W0201s1   Access to a protected member %s of a client classs   protected-accesss   Used when a protected member (i.e. class member with a name beginning with an underscore) is access outside the class or a descendant of the class where it's defined.t   W0212s   Method has no arguments   no-method-argumentsb   Used when a method which should have the bound instance as first argument has no argument defined.t   E0211s+   Method should have "self" as first arguments   no-self-arguments   Used when a method has an attribute different the "self" as first argument. This is considered as an error since this is a so common convention that you shouldn't break it!t   E0213s0   Class method %s should have %s as first arguments   bad-classmethod-arguments   Used when a class method has a first argument named differently than the value specified in valid-classmethod-first-arg option (default to "cls"), recommended to easily differentiate them from regular instance methods.t   C0202s4   Metaclass method %s should have %s as first arguments   bad-mcs-method-arguments   Used when a metaclass method has a first argument named differently than the value specified in valid-classmethod-first-arg option (default to "cls"), recommended to easily differentiate them from regular instance methods.t   C0203s:   Metaclass class method %s should have %s as first arguments   bad-mcs-classmethod-arguments   Used when a metaclass class method has a first argument named differently than the value specified in valid-metaclass-classmethod-first-arg option (default to "mcs"), recommended to easily differentiate them from regular instance methods.t   C0204s'   Static method with %r as first arguments   bad-staticmethod-arguments   Used when a static method has "self" or a value specified in valid-classmethod-first-arg option or valid-metaclass-classmethod-first-arg option as first argument.t   W0211s   Method could be a functions   no-self-usesY   Used when a method doesn't use its bound instance, and so could be written as a function.t   R0201s#   Parameters differ from %s %r methods   arguments-differst   Used when a method has a different number of arguments than in the implemented interface or in an overridden method.t   W0221s#   Signature differs from %s %r methods   signature-differssg   Used when a method signature is different than in the implemented interface or in an overridden method.t   W0222s7   Method %r is abstract in class %r but is not overriddens   abstract-methodsb   Used when an abstract method (i.e. raise NotImplementedError) is not overridden in concrete class.t   W0223s0   __init__ method from base class %r is not calleds   super-init-not-calledsa   Used when an ancestor class method has an __init__ method which is not called by a derived class.t   W0231s   Class has no __init__ methods   no-initsE   Used when a class has no __init__ method, neither its parent classes.t   W0232s9   __init__ method from a non direct base class %r is calleds   non-parent-init-calledsn   Used when an __init__ method is called on a class which is not in the direct ancestors for the analysed class.t   W0233s%   Useless super delegation in method %rs   useless-super-delegations   Used whenever we can detect that an overridden method is useless, relying on super() delegation to do the same thing as another method from the MRO.t   W0235sC   Invalid object %r in __slots__, must contain only non empty stringss   invalid-slots-objects=   Used when an invalid (non-string) object occurs in __slots__.t   E0236s4   Assigning to attribute %r not defined in class slotss   assigning-non-slotsC   Used when assigning to an attribute not defined in the class slots.t   E0237s   Invalid __slots__ objects   invalid-slotssh   Used when an invalid __slots__ is found in class. Only a string, an iterable or a sequence is permitted.t   E0238s$   Inheriting %r, which is not a class.s   inherit-non-classs?   Used when a class inherits from something which is not a class.t   E0239s1   Inconsistent method resolution order for class %rs   inconsistent-mros>   Used when a class has an inconsistent method resolution order.t   E0240s   Duplicate bases for class %rs   duplicate-basess&   Used when a class has duplicate bases.t   E0241s9   Consider using a decorator instead of calling classmethods   no-classmethod-decoratorsG   Used when a class method is defined without using the decorator syntax.t   R0202s:   Consider using a decorator instead of calling staticmethods   no-staticmethod-decoratorsH   Used when a static method is defined without using the decorator syntax.t   R0203s/   Class __slots__ should be a non-string iterables   single-string-used-for-slotssH   Used when a class __slots__ is a simple string, rather than an iterable.t   C0205t   ScopeAccessMapc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s'   Store the accessed variables per scope.c         C   s   t  j d    |  _ d  S(   Nc           S   s   t  j t  S(   N(   t   collectionst   defaultdictt   list(    (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   <lambda>%  s    (   R   R   t   _scopes(   R4   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   __init__#  s    c         C   s;   t  |  } | d k r d S|  j | | j j |  d S(   s   Set the given node as accessed.N(   R   R&   R   t   attrnameR*   (   R4   RO   t   frame(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   set_accessed(  s    c         C   s   |  j  j | i   S(   s/   Get the accessed variables for the given scope.(   R   t   get(   R4   t   scope(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   accessed1  s    (   t   __name__t
   __module__t   __doc__R   R   R   (    (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyR      s   			t   ClassCheckerc        
   B   s  e  Z d  Z e f 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 f Z	 dA d  Z e j d    Z e j d    Z d    Z d!   Z d"   Z d#   Z d$   Z e Z d%   Z d&   Z d'   Z d(   Z d)   Z d*   Z d+   Z e d, d- d.  d/    Z d0   Z d1   Z  d2   Z! d3   Z" d4   Z# d5 d6  Z$ d7   Z% d8   Z& d9   Z' d:   Z( d;   Z) d<   Z* RS(B   s   checks for :
    * methods without self as first argument
    * overridden methods signature
    * access only to existent members via self
    * attributes not defined in the __init__ method
    * unreachable code
    t   classesis   defining-attr-methodsR   t   __new__t   setUpt   defaultt   csvRL   s   <method names>t   metavarsG   List of method names used to declare (i.e. assign) instance attributes.t   helps   valid-classmethod-first-argR   s   <argument names>s=   List of valid names for the first argument in a class method.s%   valid-metaclass-classmethod-first-argt   mcssG   List of valid names for the first argument in a metaclass class method.s   exclude-protectedt   _asdictt   _fieldst   _replacet   _sourcet   _makes   <protected access exclusions>sQ   List of member names, which should be excluded from the protected access warning.c         C   s2   t  j |  |  t   |  _ g  |  _ d  |  _ d  S(   N(   R	   R   R   t	   _accessedt   _first_attrsR&   t   _meth_could_be_func(   R4   t   linter(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyR   g  s    	c         C   s   t  |  d d d  S(   Ns   dummy-variables-rgxR   (   R   R&   (   R4   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt
   _dummy_rgxm  s    c         C   s   t  |  d d t S(   Ns   ignore-mixin-membersR   (   R   R?   (   R4   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   _ignore_mixinr  s    c         C   s   |  j  |  | j d k rl t |  rl y | j d  Wql t j k
 rh |  j d d | d | ql Xn  |  j |  |  j |  |  j	 |  d S(   s&   init visit variable _accessed
        t   classR   s   no-initR,   RO   N(
   t   _check_bases_classesRL   R   t
   local_attrR(   R   t   add_messaget   _check_slotst   _check_proper_basest   _check_consistent_mro(   R4   RO   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   visit_classdefw  s     c         C   s~   y | j    Wni t k
 r= |  j d d | j d | n= t k
 ri |  j d d | j d | n t k
 ry n Xd S(   s<   Detect that a class has a consistent mro or duplicate bases.s   inconsistent-mroR,   RO   s   duplicate-basesN(   t   mroR   R   R+   R   t   NotImplementedError(   R4   RO   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyR     s    c         C   s   x | j  D] } t |  } | t j d f k r7 q
 n  t | t j  re | j d t f  re q
 n  t | t j	  s t
 |  r
 |  j d d | j   d | q
 q
 Wd S(   s`   
        Detect that a class inherits something which is not
        a class or a type.
        s   %s.types   inherit-non-classR,   RO   N(   t   basesR   R(   t   YESR&   R'   R   t   is_subtype_ofR   R`   R   R   t	   as_string(   R4   RO   t   baset   ancestor(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyR     s    c   
         s  |  j  r& | j d j   d k r& d S|  j j |  } | j d k rZ |  j | |  n  |  j j d  sp d S|  j	 j
   | j   } xt j | j  D]o\ } } g  | D]@ } t | j   t j t j f  r | j   | k r | ^ q } | s q n  t   f d   | D  r"q n  x | j |  D]L } t } x3 | j | D]$ }	 |	 j   j   k rLt } qLqLW| r2Pq2q2Wy | j |  Wq t j k
 r	xa | D]U }	 |	 j   j   k rt |	 j   |    rqn  |  j d d | d |	 qqWq Xq Wd S(	   s   close a class node:
        check that instance attributes are defined in __init__ and check
        access to existent members
        it   mixinNt	   metaclasss   attribute-defined-outside-initc         3   s$   |  ] } | j    j   k Vq d  S(   N(   R   R+   (   R:   RO   (   t   defining_methods(    s6   lib/python2.7/site-packages/pylint/checkers/classes.pys	   <genexpr>  s   R,   RO   (   R   R+   t   lowerR   R   RL   t   _check_accessed_membersR   t   is_message_enabledt   configt   defining_attr_methodst   rootRq   t	   iteritemst   instance_attrsR'   t	   statementR(   t   Deletet	   AugAssignR^   t   instance_attr_ancestorsR@   R   R?   R   R   R   R   (
   R4   t   cnodeR   t   current_moduleR   t   nodest   nt   parentt   attr_definedRO   (    (   R  s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   leave_classdef  sF    ""	c         C   s  | j    s d S|  j |  | j j   } t |  _ |  j | | j d k  | j d k rn |  j	 |  d Sxq | j
 | j  D]] } y | | j } Wn t k
 r q n Xt | t j  s q n  |  j | | d |  Pq W| j rOxa | j j D]P } t | t j  r#| j d k r#d St | t j  r | j d k r d Sq Wn  y | j | j  d	 } | j   } t | t j  r| j d
 k r| j j   } n  t | t j  r| j | j    r| j   j | j f } |  j d d | d | n  Wn t j k
 rn Xd S(   s"   check method arguments, overridingNR  R   Re   t   gettert   settert   deletert   propertyi    RK   s   method-hiddenR,   RO   (   R  R  R  (   t	   is_methodt   _check_useless_super_delegationR  R   R?   R   t   _check_first_arg_for_typeRL   R+   t   _check_initt   local_attr_ancestorst   KeyErrorR'   R(   R   t   _check_signatureR   R  t	   AttributeR   R)   t   instance_attrR`   R   t   qnameR  t
   fromlinenoR   R   (   R4   RO   R   Re   t	   meth_nodet	   decoratort   overridden_frameR,   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   visit_functiondef  sJ    		! c         C   s(  | j    s d S| j r d S| j } t |  d k r< d S| d } t | t j t j f  se d S| j } t | t j	  s d St | j
 t j  s d Sy t | j
 j j    } Wn t j k
 r d SXt | t j  s d S| j
 j | j k r d S| j j   } | j | k r"d St | j t j  s;d S| j j | j k rTd S| j j   } xr | j | j  D]^ } y | | j }	 Wn t k
 rqvn Xt |	 t j  sd St |	 j | j  rd SPqvWt | j  }
 t  |  } t! |
 |  r$|  j" d d | d | j f n  d S(   sQ  Check if the given function node is an useless method override

        We consider it *useless* if it uses the super() builtin, but having
        nothing additional whatsoever than not implementing the method at all.
        If the method uses super() to delegate an operation to the rest of the MRO,
        and if the method called is the same as the current one, the arguments
        passed to super() are the same as the parameters that were passed to
        this method, then the method could be removed altogether, by letting
        other implementation to take precedence.
        Ni   i    s   useless-super-delegationRO   R,   (#   R  R   t   bodyt   lenR'   R(   t   Exprt   ReturnR%   R   R   R%  R   t   exprR   R   R   t   SuperR   R+   R  R   t   mro_pointerRL   R   R   R"  R#  R   Rp   R,   R9   R3   RI   R   (   R4   t   functionR-  R  R.   t
   super_callt   current_scopeR   Re   R)  Rz   R,   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyR    s\    		
	c         C   sI  d | j  k r d  Sx/| j d  D]} | t j k r> q# n  t |  rq t |  rq |  j d d | q# n  t | t j  r |  j d d | q# n  t	 | d  s q# n  t | t j
  r g  | j D] } | d ^ q } n | j   } | t j k rd  Sx9 | D]1 } y |  j |  Wqt j k
 r<qqXqWq# Wd  S(   Nt	   __slots__s   invalid-slotsRO   s   single-string-used-for-slotst   iteredi    (   t   localst   igetattrR(   R   R   R   R   R'   R_   t   hasattrt   Dictt   itemsR8  t   _check_slots_eltR   (   R4   RO   R   t   itemt   valuest   elt(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyR   l  s.    #c         C   s   x | j    D] } | t j k r( q n  t | t j  sQ t | j t j  rv |  j d d | j	   d | q n  | j s |  j d d | j	   d | q q Wd  S(   Ns   invalid-slots-objectR,   RO   (
   R   R(   t   UninferableR'   R_   R%   Rq   t   string_typesR   R  (   R4   RA  R   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyR>    s    	c         C   s   | j    r | j j d k	 r. |  j j   n  |  j j d  sD d S| j j   } |  j	 r | j
 d k r | j t k r | j   p t | | j  p t |  p t j o t |  r |  j d d | q n  d S(   s   on method node, check if this method couldn't be a function

        ignore class, static and abstract methods, initializer,
        methods overridden from a parent class.
        s   no-self-useNRK   RO   (   R  R,   R&   R   t   popR   R	  R  R   R   RL   R+   R
   t   is_abstractR   R   Rq   t   PY3R   R   (   R4   RO   t
   class_node(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   leave_functiondef  s    c         C   sJ   |  j  |  r# |  j j |  d S|  j j d  s9 d S|  j |  d S(   s   check if the getattr is an access to a class member
        if so, register it. Also check for access to protected
        class member from outside its class (but ignore __special__
        methods)
        Ns   protected-access(   t   _uses_mandatory_method_paramR   R   R   R	  t!   _check_protected_attribute_access(   R4   RO   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   visit_attribute  s    c         C   sK   t  | j   t j  r: |  j |  r: |  j j |  n  |  j |  d  S(   N(   R'   t   assign_typeR(   R  RI  R   R   t   _check_in_slots(   R4   RO   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   visit_assignattr  s    c            sM  t    j  } | rIt | t j  rI| j } d | j k sI | j rM d S| j   } | d k ri d St
 d   | j   D  r d St
   f d   | D  sIt
 d   | D  sFt   j |  r d S  j | j k r t |   j  r d S  j d k r!t |   j j  r!d S|  j d d   j f d	   qFqIn  d S(
   sU    Check that the given AssignAttr node
        is defined in the class slots.
        R7  Nc         s   s-   |  ]# } d  | j  k o$ | j d k Vq d S(   R7  RZ   N(   R9  R+   (   R:   R  (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pys	   <genexpr>  s   c         3   s!   |  ] } | j    j k Vq d  S(   N(   R%   R   (   R:   t   slot(   RO   (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pys	   <genexpr>  s    c         s   s   |  ] } | j  d  k Vq d S(   t   __dict__N(   R%   (   R:   RO  (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pys	   <genexpr>  s    t	   __class__s   assigning-non-slotR,   RO   (   R   R1  R'   R(   R   R   R9  t   newstyleR   R&   R^   t	   ancestorsR   R   R   R   R  R%   R   (   R4   RO   R   R   R   (    (   RO   s6   lib/python2.7/site-packages/pylint/checkers/classes.pyRM    s.    		s   protected-accesss   no-classmethod-decorators   no-staticmethod-decoratorc         C   sT   |  j  |  | j d } t | t j  s0 d  S|  j |  rC d  S|  j |  d  S(   Ni    (   t   _check_classmethod_declarationt   targetsR'   R(   t
   AssignAttrRI  RJ  (   R4   t   assign_nodeRO   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   visit_assign  s    c            s   t  | j t j  s d S| j j } t  | t j  sG | j d	 k rK d S| j d k r` d n d } | j   } t  | t j  s d S| j j	 d } t  | t j  s d S| j   t
   f d   | j   D  r |  j | d | j d n  d S(
   s[  Checks for uses of classmethod() or staticmethod()

        When a @classmethod or @staticmethod decorator should be used instead.
        A message will be emitted only if the assignment is at a class scope
        and only if the classmethod's argument belongs to the class where it
        is defined.
        `node` is an assign node.
        NRJ   t   staticmethods   no-classmethod-decorators   no-staticmethod-decoratori    c         3   s   |  ] }   | j  k Vq d  S(   N(   R+   (   R:   t   member(   t   method_name(    s6   lib/python2.7/site-packages/pylint/checkers/classes.pys	   <genexpr>  s   RO   (   RJ   RY  (   R'   R%   R(   R   R   R)   R+   R   R`   R,   R^   t	   mymethodsR   RU  (   R4   RO   R   t   msgt   parent_classt   classmeth_arg(    (   R[  s6   lib/python2.7/site-packages/pylint/checkers/classes.pyRT    s$    		c         C   s}  | j  } t |  ry| |  j j k ryt |  } | j j   } | d k rk |  j d d | d | d St	 | j t
 j  r t	 | j j t
 j  r | j j j d k r d S|  j | j  r d S| | j k p | | j k sy| j j   } t	 | t
 j  rZt | j  d k rZt	 | j d t
 j  rZ| j d j } t | |  rZd Sn  |  j d d | d | qyn  d S(   s  Given an attribute access node (set or get), check if attribute
        access is legitimate. Call _check_first_attr with node before calling
        this method. Valid cases are:
        * self._attr in a method or cls._attr in a classmethod. Checked by
        _check_first_attr.
        * Klass._attr inside "Klass" class.
        * Klass2._attr inside "Klass" class when Klass2 is a base class of
            Klass.
        s   protected-accessRO   R,   NR   i   i    (   R   R   R
  t   exclude_protectedR   R1  R  R&   R   R'   R(   R   R   R)   R+   t   _is_type_self_callt	   basenamesR  R  t   AssignR.  RU  t
   AssignNameR   (   R4   RO   R   R   t   calleet   stmtR+   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyRJ    s.    
	c         C   sb   t  | t j  oa t  | j t j  oa | j j d k oa t | j  d k oa |  j | j d  S(   NRL   i   i    (	   R'   R(   R   R   R)   R+   R.  R,   t   _is_mandatory_method_param(   R4   R1  (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyRa  Q  s    'c         C   s=   |  j  r9 | j |  j  d k s- |  j  d r9 t |  _ n  d S(   sX   check if the name handle an access to a class member
        if so, register it
        iN(   R   R+   R@   R   (   R4   RO   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt
   visit_nameW  s    c      	   C   s  d
 } xt  j |  D]\ } } y | j |  w Wn t j k
 rL n Xy t | j |   w Wn t k
 rz n Xy | j |  } Wn t j k
 r q Xg  | D] } | | k r | ^ q } | s q n  | d j	   } g  t
 |  D]0 \ }	 } |	 d k s| j	   | k	 r | ^ q } t |  d k r | d }
 |
 j   } |
 j } xp | D]e } | j   | k ra| j | k  rat j | j   |
 |  ra|  j d d | d | | f qaqaWq q Wd	 S(   s'   check that accessed members are definedt   AttributeErrort	   Exceptiont   BaseExceptioni    i   s   access-member-before-definitionRO   R,   N(   Ri  Rj  Rk  (   Rq   R  R   R(   R   R   R  R   R&  R   t	   enumerateR.  R   R(  t   are_exclusiveR  R   (   R4   RO   R   t   excsR   R  t   defstmtsRf  R   t   it   defstmtR   t   lnot   _node(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyR  _  s>    %*
	!i    c         C   s  | j  j  d k r d S| j  j  o/ | j   d } |  j j |  |  j d } | j d k r | d k s | |  j j k s | |  j j k r |  j	 d d | d | d Sd |  j d <n | j  j  s |  j	 d	 d | n | r<| j d
 k r|  j
 | |  j j | d | j  q|  j
 | |  j j | d | j  nV | j d
 k rp|  j
 | |  j j | d | j  n" | d k r|  j	 d d | n  d S(   sl  check the name of first argument, expect:

        * 'self' for a regular method
        * 'cls' for a class method or a metaclass regular method (actually
          valid-classmethod-first-arg value)
        * 'mcs' for a metaclass class method (actually
          valid-metaclass-classmethod-first-arg)
        * not one of the above for a static method
        Ni    iRY  R4   s   bad-staticmethod-argumentR,   RO   s   no-method-argumentRJ   s   bad-mcs-classmethod-arguments   bad-mcs-method-arguments   bad-classmethod-arguments   no-self-argument(   R,   R&   t   argnamesR   R*   RL   R
  t   valid_classmethod_first_argt%   valid_metaclass_classmethod_first_argR   t   _check_first_arg_configR+   (   R4   RO   R  t	   first_argt   first(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyR     sB    c         C   s   | | k r t  |  d k r1 t | d  } n1 d j d   | d  D  } d | | d f } |  j | d | | f d | n  d  S(	   Ni   i    s   , c         s   s   |  ] } t  |  Vq d  S(   N(   t   repr(   R:   t   v(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pys	   <genexpr>  s    is   %s or %rR,   RO   (   R.  Rz  t   joinR   (   R4   Ry  R
  RO   t   messageR[  t   valid(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyRw    s    c         C   s   d   } t  |  r d St t | |  j   d d   } xl | D]d \ } } | j j   } | | k rq qD n  | | j k r qD n  |  j d d | d | | j f qD Wd S(   s^   check that the given class node implements abstract methods from
        base classes
        c         S   s   |  j  d t  S(   Nt   pass_is_abstract(   RE  R@   (   RK   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyRE    s    Nt   keyc         S   s   |  d S(   Ni    (    (   R?  (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyR     s    s   abstract-methodRO   R,   (	   R   t   sortedR   R=  R  R   R9  R   R+   (   R4   RO   RE  R   R+   RK   t   owner(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyR     s    	c   
      C   sT  |  j  j d  r* |  j  j d  r* d S| j j   } t |  } t |  } x| j t j  D]v} | j	 } t
 | t j  sd | j d k r qd n  t
 | j t j  r t
 | j j	 t j  r | j j	 j d k r d Sy x | j j   D] } | t j k rq n  t
 | t j  r[t
 | j t j  r[t | j  r[| j j d k r[d St
 | t j  rqd Sy | | =Wq t k
 r| | k r|  j d d | d | j qq Xq WWqd t j k
 rqd qd Xqd Wxo t j |  D]^ \ } } t |  }	 | j d k s|	 r0|	 j d k r0qn  |  j d d | j d | qWd S(	   sW   check that the __init__ method call super or ancestors'__init__
        method
        s   super-init-not-calleds   non-parent-init-calledNR   R   RO   R,   RZ   (   R   R	  R  R   t   _ancestors_to_callt   dictR   R(   R   R   R'   R%  R   R1  R)   R+   R   RB  R   R   R`   R   R   R2  R#  R   R   Rq   R  R   (
   R4   RO   t
   klass_nodet   to_callt   not_called_yetRf  R1  R   RK   R   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyR!    sN    	$c         C   s~  t  | t j  o! t  | t j  sG |  j d d | | f d | d S| j   } t | |  } t | |  } | j j d k s | j j d k r d St | j	  r d S| j
 r x< | j
 j D]+ } t  | t j  r | j d k r d Sq Wn  t | | d |  j r1|  j d d | | j	 f d | nI t | j j  t | j j  k  rz|  j d d | | j	 f d | n  d S(	   s@   check that the signature of the two given methods match
        s   method-check-failedR,   RO   NR  Rv   s   arguments-differs   signature-differs(   R'   R(   R   R   t   instantiate_classR   R,   R&   R   R+   R   R  R%  R   R   R   R.  t   defaults(   R4   t   method1t	   refmethodt
   class_typeR   t   instanceR*  (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyR$  !  s6    $		
$c         C   s   |  j  | j  S(   s   Check that attribute lookup name use first attribute variable name

        Name is `self` for method, `cls` for classmethod and `mcs` for metaclass.
        (   Rg  R1  (   R4   RO   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyRI  H  s    c         C   s/   |  j  o. t | t j  o. | j |  j  d k S(   s   Check if astroid.Name corresponds to first attribute variable name

        Name is `self` for method, `cls` for classmethod and `mcs` for metaclass.
        i(   R   R'   R(   R)   R+   (   R4   RO   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyRg  O  s    (   R   R   R   (   R   (   R   (   R   R   R   R   R   N(+   R   R   R   R   t   __implements__R+   t   MSGSt   msgst   priorityt   optionsR&   R   R   t   cachedpropertyR   R   R   R   R   R  R,  t   visit_asyncfunctiondefR  R   R>  RH  RK  RN  RM  R   RX  RT  RJ  Ra  Rh  R  R   Rw  R   R!  R$  RI  Rg  (    (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyR   6  sp   	





				;	5	W	 					&		#	8			27	
		4	'	t   SpecialMethodsCheckerc           B   s   e  Z d  Z e f Z d Z i d d d e i d d g d 6f d 6d	 d
 d i d g d 6f d 6d d d i  f d 6Z d Z e	 d
 d d  d    Z
 e
 Z d   Z e d    Z d   Z d   Z RS(   sO   Checker which verifies that special methods
    are implemented correctly.
    R   s   __iter__ returns non-iterators   non-iterator-returnedsa   Used when an __iter__ method returns something which is not an iterable (i.e. has no `%s` method)t   W0234t   E0234t	   old_namest   E0301s6   The special method %r expects %s param(s), %d %s givens#   unexpected-special-method-signatures   Emitted when a special method was defined with an invalid number of parameters. If it has too few or too many, it might not work at all.t   E0235s   bad-context-managert   E0302s,   __len__ does not return non-negative integers   invalid-length-returnedsQ   Used when an __len__ method returns something which is not a non-negative integert   E0303ic         C   sq   | j    s d  S| j d k r/ |  j |  n  | j d k rN |  j |  n  | j t k rm |  j |  n  d  S(   Nt   __iter__t   __len__(   R  R+   t   _check_itert
   _check_lenR
   t"   _check_unexpected_method_signature(   R4   RO   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyR,  r  s    c   
      C   s}  t  | j } | d  k r d  S| j j r; | j j r; d  St | t d g  r` | j j } n | j j d } t |  t | j j  } t | j j  } | | } t	 | t
  r | | k } d | } n` | | } | d k r t } nA | d k  rt } n, | d k r0| | d k p)| j j } n  | ry| d k rHd n d }	 |  j d d | j | | |	 f d	 | n  d  S(
   Ns   .staticmethodi   s   between %d or %di    t   wast   weres#   unexpected-special-method-signatureR,   RO   (   R   R+   R&   R,   R6   R   R   R.  R  R'   Rc   R@   R?   R   (
   R4   RO   t   expected_paramst   all_argst	   mandatoryt   optionalt   current_paramst   emitt   restt   verb(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyR    s4    

		 c         C   s   |  t  j k r t St |  t  r& t St |  t  j  rg y |  j t  t SWq t  j k
 rc q Xnh t |  t  j	  r |  j
   } | r t | t  j	  r y | j t  t SWq t  j k
 r q Xq n  t S(   N(   R(   R   R?   R'   R   R   R   t   NEXT_METHODR   R`   R  R@   (   RO   R  (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   _is_iterator  s&    
c         C   sG   t  | |  } | d  k	 rC |  j |  sC |  j d d | qC n  d  S(   Ns   non-iterator-returnedRO   (   R   R&   R  R   (   R4   RO   R   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyR    s    c         C   s   t  | |  } | s% | t j k r) d  St | t j  ra | j d k ra t | t j  ra d  St | t j  s |  j d d | d  S| j } t | t	 j
  s | d k  r |  j d d | n  d  S(   Nt   ints   invalid-length-returnedRO   i    (   R   R(   RB  R'   R   R+   R_   R   R%   Rq   t   integer_types(   R4   RO   R   R%   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyR    s    	(   R  s   non-iterator-returned(   R  s   non-iterator-returned(   R  s   bad-context-manager(   R   R   R   R   R  R+   R  R  R  R   R,  R  R  RY  R  R  R  (    (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyR  X  s4   		-	R   c         C   s^   i  } xQ |  j  d t  D]= } y t | j |   | | <Wq t j k
 rU q q Xq W| S(   s   return a dictionary where keys are the list of base classes providing
    the queried method, and so that should/may be called from the method node
    t   recurs(   RS  R@   R   R:  R(   R   (   R  RK   R  t	   base_node(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyR    s    c         C   sC   x- |  j  |  D] } t | t j  r | Sq Wt j |   d S(   s^   get astroid for <method_name> on the given class node, ensuring it
    is a Function node
    N(   R   R'   R(   t   FunctionR   (   RO   R[  t	   node_attr(    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   node_method  s    c         C   s*   |  j  t |    |  j  t |    d S(   s.   required method to auto register this checker N(   t   register_checkerR   R  (   R   (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   register  s    (G   R   t
   __future__R    R   t   sysRq   R(   t   astroid.basesR   R   t   astroid.exceptionsR   R   R   R   t   astroid.scoped_nodesR   t   pylint.interfacesR   t   pylint.checkersR	   t   pylint.checkers.utilsR
   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t   pylint.utilsR   t   version_infoR  R   t
   namedtupleR!   R"   R3   R9   RI   RN   RR   RW   Rp   R|   R   R   R   R   R   R   R&   R   R   R  RZ   R   R   R  R  R  R  (    (    (    s6   lib/python2.7/site-packages/pylint/checkers/classes.pyt   <module>   s
  j					$				,		1					
	



























   %		