ó
'![c           @` s“   d  Z  d d l m Z m Z m Z d d l Z d d l m Z d d l m	 Z	 d d l m
 Z d d l j j Z
 d e	 f d „  ƒ  YZ d	 „  Z d S(
   sH   Pylint plugin for checking in Sphinx, Google, or Numpy style docstrings
i    (   t   print_functiont   divisiont   absolute_importN(   t   IAstroidChecker(   t   BaseChecker(   t   utilst   DocstringParameterCheckerc           B` só  e  Z d  Z e Z d Z i dX d 6dY d	 6dZ d 6d[ d 6d d d i d\ g d 6f d 6d] d 6d d d i d^ g d 6f d" 6d_ d& 6d' d( d) i d` g d 6f d+ 6d, d- d. i da g d 6f d0 6db d4 6dc d8 6Z d9 i e d: 6d; d< 6d= d> 6d? d@ 6f dA i e d: 6d; d< 6d= d> 6dB d@ 6f dC i e d: 6d; d< 6d= d> 6dD d@ 6f dE i e d: 6d; d< 6d= d> 6dF d@ 6f f Z dG Z	 dH dI h Z
 dJ dK h Z dL „  Z dM „  Z dN „  Z dO „  Z dP „  Z dQ „  Z dR „  Z dS „  Z dd dT „ Z dU „  Z dV „  Z dW „  Z RS(e   sÜ  Checker for Sphinx, Google, or Numpy style docstrings

    * Check that all function, method and constructor parameters are mentioned
      in the params and types part of the docstring.  Constructor parameters
      can be documented in either the class docstring or ``__init__`` docstring,
      but not both.
    * Check that there are no naming inconsistencies between the signature and
      the documentation, i.e. also report documented parameters that are missing
      in the signature. This is important to find cases where parameters are
      renamed only in the code, not in the documentation.
    * Check that all explicitly raised exceptions in a function are documented
      in the function docstring. Caught exceptions are ignored.

    Activate this checker by adding the line::

        load-plugins=pylint.extensions.docparams

    to the ``MASTER`` section of your ``.pylintrc``.

    :param linter: linter object
    :type linter: :class:`pylint.lint.PyLinter`
    t   parameter_documentations@   "%s" has constructor parameters documented in class and __init__s   multiple-constructor-docsA   Please remove parameter declarations in the class or constructor.t   W9005s#   "%s" not documented as being raiseds   missing-raises-docs:   Please document exceptions for all raised exception types.t   W9006s   Redundant returns documentations   redundant-returns-docs>   Please remove the return/rtype documentation from this method.t   W9008s   Redundant yields documentations   redundant-yields-docs8   Please remove the yields documentation from this method.t   W9010s   Missing return documentations   missing-return-docs8   Please add documentation about what this method returns.t   W9007s   missing-returns-doct	   old_namest   W9011s!   Missing return type documentations   missing-return-type-docs1   Please document the type returned by this method.t   W9012s   Missing yield documentations   missing-yield-docs:   Please add documentation about what this generator yields.t   W9009s   missing-yields-doct   W9013s    Missing yield type documentations   missing-yield-type-docs0   Please document the type yielded by this method.t   W9014s'   "%s" missing in parameter documentations   missing-param-docs5   Please add parameter declarations for all parameters.t   W9003t   W9015s,   "%s" missing in parameter type documentations   missing-type-docs:   Please add parameter type declarations for all parameters.t   W9004t   W9016s)   "%s" differing in parameter documentations   differing-param-docs-   Please check parameter names in declarations.t   W9017s.   "%s" differing in parameter type documentations   differing-type-docs2   Please check parameter names in type declarations.t   W9018s   accept-no-param-doct   defaultt   ynt   types   <y or n>t   metavarsm   Whether to accept totally missing parameter documentation in the docstring of a function that has parameters.t   helps   accept-no-raise-docso   Whether to accept totally missing raises documentation in the docstring of a function that raises an exception.s   accept-no-return-docso   Whether to accept totally missing return documentation in the docstring of a function that returns a statement.s   accept-no-yields-docsW   Whether to accept totally missing yields documentation in the docstring of a generator.iþÿÿÿt   __init__t   __new__t   selft   clsc         C` sF   t  j | j ƒ } |  j | | ƒ |  j | | ƒ |  j | | ƒ d S(   s¿   Called for function and method definitions (def).

        :param node: Node for a function or method definition in the AST
        :type node: :class:`astroid.scoped_nodes.Function`
        N(   R   t   docstringifyt   doct   check_functiondef_paramst   check_functiondef_returnst   check_functiondef_yields(   R    t   nodet   node_doc(    (    s:   lib/python2.7/site-packages/pylint/extensions/docparams.pyt   visit_functiondef…   s    c         C` sÐ   d  } | j |  j k r³ t j | ƒ } | d  k	 r³ t j | j ƒ } |  j | | | ƒ | j	 ƒ  ps | j
 ƒ  ps d  } | j	 ƒ  p‘ | j
 ƒ  p‘ d  } |  j | | j | | ƒ q³ n  |  j | | j | | ƒ d  S(   N(   t   Nonet   namet   constructor_namest   checker_utilst   node_frame_classR   R"   R#   t   check_single_constructor_paramst
   has_paramst   params_documented_elsewheret   check_arguments_in_docstringt   args(   R    R'   R(   t   node_allow_no_paramt
   class_nodet	   class_doct   class_allow_no_param(    (    s:   lib/python2.7/site-packages/pylint/extensions/docparams.pyR$      s     c         C` s   | j  r | j ƒ  s" | j ƒ  r& d  S| j t j ƒ } | j ƒ  sP | j ƒ  r} t d „  | Dƒ ƒ r} |  j	 d d | ƒn  d  S(   Nc         s` s   |  ] } t  j | ƒ Vq d  S(   N(   R   t   returns_something(   t   .0t   ret_node(    (    s:   lib/python2.7/site-packages/pylint/extensions/docparams.pys	   <genexpr>²   s    s   redundant-returns-docR'   (
   t   supports_yieldst   is_generatort   is_abstractt   nodes_of_classt   astroidt   Returnt   has_returnst	   has_rtypet   anyt   add_message(   R    R'   R(   t   return_nodes(    (    s:   lib/python2.7/site-packages/pylint/extensions/docparams.pyR%   «   s    c         C` sY   | j  s | j ƒ  r d  S| j ƒ  s2 | j ƒ  rU | j ƒ  rU |  j d d | ƒn  d  S(   Ns   redundant-yields-docR'   (   R;   R=   t
   has_yieldst   has_yields_typeR<   RD   (   R    R'   R(   (    (    s:   lib/python2.7/site-packages/pylint/extensions/docparams.pyR&   ·   s    c         C` sÍ   | j  ƒ  } t | t j ƒ s" d  St j | ƒ } | s; d  S| j se t j | ƒ } | re | } qe n  t j | j ƒ } | j	 ƒ  s£ | j rŸ |  j
 | | ƒ n  d  S| j ƒ  } | | } |  j | | ƒ d  S(   N(   t   framet
   isinstanceR?   t   FunctionDefR   t   possible_exc_typesR#   t   get_setters_propertyR"   t   is_validt   _handle_no_raise_doct
   exceptionst   _add_raise_message(   R    R'   t	   func_nodet   expected_excst	   property_R#   t
   found_excst   missing_excs(    (    s:   lib/python2.7/site-packages/pylint/extensions/docparams.pyt   visit_raiseÁ   s$    		
c         C` sß   t  j | ƒ s d  S| j ƒ  } t | t j ƒ s5 d  St  j | j ƒ } | j ƒ  rd |  j	 j
 rd d  St j | ƒ } | j ƒ  pŽ | j ƒ  oŽ | s§ |  j d d | ƒn  | j ƒ  pÂ | j ƒ  oÂ | sÛ |  j d d | ƒn  d  S(   Ns   missing-return-docR'   s   missing-return-type-doc(   R   R8   RH   RI   R?   RJ   R"   R#   RM   t   configt   accept_no_return_docR-   t   decorated_with_propertyRA   t   has_property_returnsRD   RB   t   has_property_type(   R    R'   RQ   R#   t   is_property(    (    s:   lib/python2.7/site-packages/pylint/extensions/docparams.pyt   visit_returnÛ   s&    
c         C` sÉ   | j  ƒ  } t | t j ƒ s" d  St j | j ƒ } | j ƒ  rQ |  j j	 rQ d  S| j
 ru | j ƒ  } | j ƒ  } n | j ƒ  } | j ƒ  } | s© |  j d d | ƒn  | sÅ |  j d d | ƒn  d  S(   Ns   missing-yield-docR'   s   missing-yield-type-doc(   RH   RI   R?   RJ   R   R"   R#   RM   RW   t   accept_no_yields_docR;   RF   RG   RA   RB   RD   (   R    R'   RQ   R#   t   doc_has_yieldst   doc_has_yields_type(    (    s:   lib/python2.7/site-packages/pylint/extensions/docparams.pyt   visit_yield÷   s&    	
c         C` s   |  j  | ƒ d  S(   N(   Ra   (   R    R'   (    (    s:   lib/python2.7/site-packages/pylint/extensions/docparams.pyt   visit_yieldfrom  s    c   
      ` s€  | j  s d S| d k r( ˆ j j } n  | j ƒ  ‰ t d „  | j Dƒ ƒ ‰  ˆ  j d „  | j Dƒ ƒ ˆ j	 j
 ƒ  } | j d k	 r¨ ˆ  j | j ƒ | j | j ƒ n  | j d k	 rÚ ˆ  j | j ƒ | j | j ƒ n  | j ƒ  \ } } | r	| r	| r	t ‰ n  ‡  ‡ ‡ ‡ f d †  } ‡  ‡ ‡ f d †  }	 | | d ˆ j	 ƒ | | d | ƒ |	 | d ˆ j	 ƒ |	 | d	 | ƒ d S(
   sª  Check that all parameters in a function, method or class constructor
        on the one hand and the parameters mentioned in the parameter
        documentation (e.g. the Sphinx tags 'param' and 'type') on the other
        hand are consistent with each other.

        * Undocumented parameters except 'self' are noticed.
        * Undocumented parameter types except for 'self' and the ``*<args>``
          and ``**<kwargs>`` parameters are noticed.
        * Parameters mentioned in the parameter documentation that don't or no
          longer exist in the function parameter list are noticed.
        * If the text "For the parameters, see" or "For the other parameters,
          see" (ignoring additional whitespace) is mentioned in the docstring,
          missing parameter documentation is tolerated.
        * If there's no Sphinx style, Google style or NumPy style parameter
          documentation at all, i.e. ``:param`` is never mentioned etc., the
          checker assumes that the parameters are documented in another format
          and the absence is tolerated.

        :param doc: Docstring for the function, method or class.
        :type doc: str

        :param arguments_node: Arguments node for the function, method or
            class constructor.
        :type arguments_node: :class:`astroid.scoped_nodes.Arguments`

        :param warning_node: The node to assign the warnings to
        :type warning_node: :class:`astroid.scoped_nodes.Node`

        :param accept_no_param_doc: Whether or not to allow no parameters
            to be documented.
            If None then this value is read from the configuration.
        :type accept_no_param_doc: bool or None
        Nc         s` s   |  ] } | j  Vq d  S(   N(   R+   (   R9   t   arg(    (    s:   lib/python2.7/site-packages/pylint/extensions/docparams.pys	   <genexpr>C  s    c         s` s   |  ] } | j  Vq d  S(   N(   R+   (   R9   Rc   (    (    s:   lib/python2.7/site-packages/pylint/extensions/docparams.pys	   <genexpr>D  s    c         ` sO   ˆ sK ˆ  |  | } | rK ˆ j  | d d j t | ƒ ƒ f d ˆ ƒqK n  d S(   s  Compare the found argument names with the expected ones and
            generate a message if there are arguments missing.

            :param set found_argument_names: argument names found in the
                docstring

            :param str message_id: pylint message id

            :param not_needed_names: names that may be omitted
            :type not_needed_names: set of str
            R3   s   , R'   N(   RD   t   joint   sorted(   t   found_argument_namest
   message_idt   not_needed_namest   missing_argument_names(   t   expected_argument_namesR    t   tolerate_missing_paramst   warning_node(    s:   lib/python2.7/site-packages/pylint/extensions/docparams.pyt   _compare_missing_argsU  s    c         ` sJ   ˆ  |  A| ˆ  } | rF ˆ j  | d d j t | ƒ ƒ f d ˆ ƒn  d S(   s”  Compare the found argument names with the expected ones and
            generate a message if there are extra arguments found.

            :param set found_argument_names: argument names found in the
                docstring

            :param str message_id: pylint message id

            :param not_needed_names: names that may be omitted
            :type not_needed_names: set of str
            R3   s   , R'   N(   RD   Rd   Re   (   Rf   Rg   Rh   t   differing_argument_names(   Rj   R    Rl   (    s:   lib/python2.7/site-packages/pylint/extensions/docparams.pyt   _compare_different_argsm  s    s   missing-param-docs   missing-type-docs   differing-param-docs   differing-type-doc(   R#   R*   RW   t   accept_no_param_docR1   t   setR3   t   updatet
   kwonlyargst   not_needed_param_in_docstringt   copyt   varargt   addt   kwargt   match_param_docst   True(
   R    R#   t   arguments_nodeRl   Rp   t   not_needed_type_in_docstringt   params_with_doct   params_with_typeRm   Ro   (    (   Rj   R    Rk   Rl   s:   lib/python2.7/site-packages/pylint/extensions/docparams.pyR2     s8    %			
		
	c         C` s>   | j  ƒ  r: | j  ƒ  r: |  j d d | j f d | ƒn  d  S(   Ns   multiple-constructor-docR3   R'   (   R0   RD   R+   (   R    R6   t   init_docR5   (    (    s:   lib/python2.7/site-packages/pylint/extensions/docparams.pyR/     s
    c         C` s$   |  j  j r d  S|  j | | ƒ d  S(   N(   RW   t   accept_no_raise_docRP   (   R    t   excsR'   (    (    s:   lib/python2.7/site-packages/pylint/extensions/docparams.pyRN   –  s    c         C` sm   | j  ƒ  r4 y | j d ƒ Wq4 t k
 r0 q4 Xn  | s> d S|  j d d d j t | ƒ ƒ f d | ƒd S(   s  
        Adds a message on :param:`node` for the missing exception type.

        :param missing_excs: A list of missing exception types.
        :type missing_excs: set(str)

        :param node: The node show the message on.
        :type node: astroid.node_classes.NodeNG
        t   NotImplementedErrorNs   missing-raises-docR3   s   , R'   (   R=   t   removet   KeyErrorRD   Rd   Re   (   R    RU   R'   (    (    s:   lib/python2.7/site-packages/pylint/extensions/docparams.pyRP   œ  s    
(   s@   "%s" has constructor parameters documented in class and __init__s   multiple-constructor-docsA   Please remove parameter declarations in the class or constructor.(   s#   "%s" not documented as being raiseds   missing-raises-docs:   Please document exceptions for all raised exception types.(   s   Redundant returns documentations   redundant-returns-docs>   Please remove the return/rtype documentation from this method.(   s   Redundant yields documentations   redundant-yields-docs8   Please remove the yields documentation from this method.(   R   s   missing-returns-doc(   s!   Missing return type documentations   missing-return-type-docs1   Please document the type returned by this method.(   R   s   missing-yields-doc(   s    Missing yield type documentations   missing-yield-type-docs0   Please document the type yielded by this method.(   R   s   missing-param-doc(   R   s   missing-type-doc(   s)   "%s" differing in parameter documentations   differing-param-docs-   Please check parameter names in declarations.(   s.   "%s" differing in parameter type documentations   differing-type-docs2   Please check parameter names in type declarations.N(   t   __name__t
   __module__t   __doc__R   t   __implements__R+   t   msgsRz   t   optionst   priorityR,   Rt   R)   R$   R%   R&   RV   R]   Ra   Rb   R*   R2   R/   RN   RP   (    (    (    s:   lib/python2.7/site-packages/pylint/extensions/docparams.pyR      sŽ                   



				
				x		c         C` s   |  j  t |  ƒ ƒ d S(   s   Required method to auto register this checker.

    :param linter: Main interface object for Pylint plugins
    :type linter: Pylint object
    N(   t   register_checkerR   (   t   linter(    (    s:   lib/python2.7/site-packages/pylint/extensions/docparams.pyt   register´  s    (   R‡   t
   __future__R    R   R   R?   t   pylint.interfacesR   t   pylint.checkersR   R   R-   t#   pylint.extensions._check_docs_utilst
   extensionst   _check_docs_utilsR   RŽ   (    (    (    s:   lib/python2.7/site-packages/pylint/extensions/docparams.pyt   <module>   s   ÿ ›