o
    g_                     @   s   d Z ddlZddlmZ ddl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 dd
lmZ G dd deZdd ZdS )zHPylint plugin for checking in Sphinx, Google, or Numpy style docstrings
    N)Optional)nodes)BaseChecker)utils)_check_docs_utils)	Docstring)IAstroidChecker)get_global_optionc                   @   s  e Zd ZdZeZdZddddddd	d
dgifddddd
dgifddddd
dgifdddd
dgifdddddZdd d!d"d#d$fd%d d!d"d&d$fd'd d!d"d(d$fd)d d!d"d*d$fd+d,d-ee	j
d.d/ffZd0Zd1d2hZd3d4hZd5ejd6d7fd8d9ZeZd:d; Zd<d= Zd>d? Zd5ejd6d7fd@dAZd5ejd6d7fdBdCZd5ejd6d7fdDdEZd5ejd6d7fdFdGZdHdI ZdJdK ZdLdM Z 	7dZdNe!dOe"j#dPe"j$dQe%e& fdRdSZ'dTdU Z(dVdW Z)dXdY Z*d7S )[DocstringParameterCheckera  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`
    parameter_documentation)z@"%s" has constructor parameters documented in class and __init__multiple-constructor-doczAPlease remove parameter declarations in the class or constructor.)z#"%s" not documented as being raisedmissing-raises-docz:Please document exceptions for all raised exception types.)zRedundant returns documentationredundant-returns-docz>Please remove the return/rtype documentation from this method.)zRedundant yields documentationredundant-yields-docz8Please remove the yields documentation from this method.zMissing return documentationmissing-return-docz8Please add documentation about what this method returns.	old_names)W9007zold-missing-returns-doc)z!Missing return type documentationmissing-return-type-docz1Please document the type returned by this method.zMissing yield documentationmissing-yield-docz:Please add documentation about what this generator yields.)W9009zold-missing-yields-doc)z Missing yield type documentationmissing-yield-type-docz0Please document the type yielded by this method.z'"%s" missing in parameter documentationmissing-param-docz5Please add parameter declarations for all parameters.)W9003zold-missing-param-docz,"%s" missing in parameter type documentationmissing-type-docz:Please add parameter type declarations for all parameters.)W9004zold-missing-type-doc)z)"%s" differing in parameter documentationdiffering-param-docz-Please check parameter names in declarations.)z."%s" differing in parameter type documentationdiffering-type-docz2Please check parameter names in type declarations.)z,"%s" useless ignored parameter documentationuseless-param-docz2Please remove the ignored parameter documentation.)z1"%s" useless ignored parameter type documentationuseless-type-docz7Please remove the ignored parameter type documentation.)W9005W9006W9008W9010W9011W9012W9013W9014W9015W9016W9017W9018W9019W9020zaccept-no-param-docTynz<y or n>zmWhether to accept totally missing parameter documentation in the docstring of a function that has parameters.)defaulttypemetavarhelpzaccept-no-raise-doczoWhether to accept totally missing raises documentation in the docstring of a function that raises an exception.zaccept-no-return-doczoWhether to accept totally missing return documentation in the docstring of a function that returns a statement.zaccept-no-yields-doczWWhether to accept totally missing yields documentation in the docstring of a generator.zdefault-docstring-typechoicer.   zRIf the docstring type cannot be guessed the specified docstring type will be used.)r/   r.   choicesr1   __init____new__selfclsnodereturnNc                 C   s   t |j| jj}t| d}|rt||jrdS t	
||j }t| d}|dkr0||k r0dS | || | || | || dS )zCalled 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`
        zno-docstring-rgxNzdocstring-min-length)r   docstringifydocconfigdefault_docstring_typer	   rematchnamechecker_utilsget_node_last_linenolinenocheck_functiondef_paramscheck_functiondef_returnscheck_functiondef_yields)r7   r9   node_docno_docstring_rgxlines	max_lines rM   Y/home/ubuntu/cloudmapper/venv/lib/python3.10/site-packages/pylint/extensions/docparams.pyvisit_functiondef   s   

z+DocstringParameterChecker.visit_functiondefc                 C   s   d }|j | jv r>t|}|d ur>t|j| jj}| 	||| |
 p*| p*d }|
 p4| p4d }| ||j|| | ||j|| d S N)rB   constructor_namesrC   node_frame_classr   r<   r=   r>   r?   check_single_constructor_params
has_paramsparams_documented_elsewherecheck_arguments_in_docstringargs)r7   r9   rI   node_allow_no_param
class_node	class_docclass_allow_no_paramrM   rM   rN   rF      s0   



z2DocstringParameterChecker.check_functiondef_paramsc                 C   sb   |j s| s| rd S |tj}| s| r/tdd |D s-| j	d|d d S d S d S )Nc                 s   s    | ]}t |V  qd S rP   )r   returns_something).0ret_noderM   rM   rN   	<genexpr>  s    

zFDocstringParameterChecker.check_functiondef_returns.<locals>.<genexpr>r   r9   )
supports_yieldsis_generatoris_abstractnodes_of_classastroidReturnhas_returns	has_rtypeanyadd_message)r7   r9   rI   return_nodesrM   rM   rN   rG     s   z3DocstringParameterChecker.check_functiondef_returnsc                 C   sD   |j r| r	d S | s| r | s| jd|d d S d S d S )Nr   r`   )ra   rc   
has_yieldshas_yields_typerb   rj   )r7   r9   rI   rM   rM   rN   rH     s   z2DocstringParameterChecker.check_functiondef_yieldsc           	      C   s   |  }t|tjsd S t|}|sd S |js!t|}|r!|}t|j| j	j
}| s9|jr7| || d S | }dd |D }|| }| || d S )Nc                 S   s   h | ]	}| d d qS ).r;   )split)r]   excrM   rM   rN   	<setcomp>8  s    z8DocstringParameterChecker.visit_raise.<locals>.<setcomp>)frame
isinstancere   FunctionDefr   possible_exc_typesr=   get_setters_propertyr<   r>   r?   is_valid_handle_no_raise_doc
exceptions_add_raise_message)	r7   r9   	func_nodeexpected_excs	property_r=   found_excs_full_namesfound_excs_class_namesmissing_excsrM   rM   rN   visit_raise  s&   

z%DocstringParameterChecker.visit_raisec                 C   s   t |sd S | }t|tjsd S t |j| jj	}|
 s&| jjr&d S t|}| s<| r5|s<| jd|d |jrAd S | sT| rK|sV| jd|d d S d S d S )Nr   r`   r   )r   r\   rr   rs   re   rt   r<   r=   r>   r?   rw   accept_no_return_docrC   decorated_with_propertyrg   has_property_returnsrj   returnsrh   has_property_type)r7   r9   r{   r=   is_propertyrM   rM   rN   visit_return<  s    

z&DocstringParameterChecker.visit_returnc                 C   s   |  }t|tjsd S t|j| jj}|	 s| jj
rd S |jr+| }| }n| }| }|s<| jd|d |sJ|jsL| jd|d d S d S d S )Nr   r`   r   )rr   rs   re   rt   r   r<   r=   r>   r?   rw   accept_no_yields_docra   rl   rm   rg   rh   rj   r   )r7   r9   r{   r=   doc_has_yieldsdoc_has_yields_typerM   rM   rN   visit_yieldS  s    

z%DocstringParameterChecker.visit_yieldc                 C   s   |  | d S rP   )r   )r7   r9   rM   rM   rN   visit_yieldfromi  s   z)DocstringParameterChecker.visit_yieldfromc                 C   s4   || | }|r| j |dt|f|d dS dS )a  Compare the found argument names with the expected ones and
        generate a message if there are arguments missing.

        :param found_argument_names: argument names found in the docstring
        :type found_argument_names: set

        :param message_id: pylint message id
        :type message_id: str

        :param not_needed_names: names that may be omitted
        :type not_needed_names: set

        :param expected_argument_names: Expected argument names
        :type expected_argument_names: set

        :param warning_node: The node to be analyzed
        :type warning_node: :class:`astroid.scoped_nodes.Node`
        , rW   r9   Nrj   joinsorted)r7   found_argument_names
message_idnot_needed_namesexpected_argument_nameswarning_nodemissing_argument_namesrM   rM   rN   _compare_missing_argsl  s   
z/DocstringParameterChecker._compare_missing_argsc                 C   s8   ||A | | }|r| j |dt|f|d dS dS )a  Compare the found argument names with the expected ones and
        generate a message if there are extra arguments found.

        :param found_argument_names: argument names found in the docstring
        :type found_argument_names: set

        :param message_id: pylint message id
        :type message_id: str

        :param not_needed_names: names that may be omitted
        :type not_needed_names: set

        :param expected_argument_names: Expected argument names
        :type expected_argument_names: set

        :param warning_node: The node to be analyzed
        :type warning_node: :class:`astroid.scoped_nodes.Node`
        r   r   Nr   )r7   r   r   r   r   r   differing_argument_namesrM   rM   rN   _compare_different_args  s   
z1DocstringParameterChecker._compare_different_argsc                 C   s0   ||@ }|r| j |dt|f|d dS dS )a#  Compare the found argument names with the ignored ones and
        generate a message if there are ignored arguments found.

        :param found_argument_names: argument names found in the docstring
        :type found_argument_names: set

        :param message_id: pylint message id
        :type message_id: str

        :param ignored_argument_names: Expected argument names
        :type ignored_argument_names: set

        :param warning_node: The node to be analyzed
        :type warning_node: :class:`astroid.scoped_nodes.Node`
        r   r   Nr   )r7   r   r   ignored_argument_namesr   existing_ignored_argument_namesrM   rM   rN   _compare_ignored_args  s   
z/DocstringParameterChecker._compare_ignored_argsr=   arguments_noder   accept_no_param_docc                    s  |j sdS |du r| jj}| }dd |jD }|dd |jD  | j }t	 }t
| d  r< fdd|D }|jdurM||j ||j |jdur^||j ||j | \}	}
|	sl|
sl|rld}|sz| |	d	| j|B || | |
d
|| t|jD ]\}}|j| r|
|j qt|jD ]\}}|j| r|
|j q|s| |
d||B || | |	d| j|| | |
d||| | |	d|| dS )a  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: :class:`Docstring`

        :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   h | ]}|j qS rM   rB   r]   argrM   rM   rN   rq     s    zIDocstringParameterChecker.check_arguments_in_docstring.<locals>.<setcomp>c                 s   s    | ]}|j V  qd S rP   r   r   rM   rM   rN   r_   	  s    zIDocstringParameterChecker.check_arguments_in_docstring.<locals>.<genexpr>zignored-argument-namesc                    s   h | ]	}  |r|qS rM   )rA   r   r   rM   rN   rq     s    Tr   r   r   r   r   r   )r=   r>   r   rU   rW   update
kwonlyargsnot_needed_param_in_docstringcopysetr	   varargaddkwargmatch_param_docsr   r   	enumerateannotationsrB   kwonlyargs_annotationsr   )r7   r=   r   r   r   tolerate_missing_paramsr   not_needed_type_in_docstring#expected_but_ignored_argument_namesparams_with_docparams_with_typeindexarg_namerM   r   rN   rV     s   *






z6DocstringParameterChecker.check_arguments_in_docstringc                 C   s0   |  r|  r| jd|jf|d d S d S d S )Nr   r   )rT   rj   rB   )r7   rZ   init_docrY   rM   rM   rN   rS   X  s
   

z9DocstringParameterChecker.check_single_constructor_paramsc                 C   s   | j jrd S | || d S rP   )r>   accept_no_raise_docrz   )r7   excsr9   rM   rM   rN   rx   ^  s   z.DocstringParameterChecker._handle_no_raise_docc                 C   sR   |  rz|d W n	 ty   Y nw |sdS | jddt|f|d dS )a  
        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: nodes.NodeNG
        NotImplementedErrorNr   r   r   )rc   removeKeyErrorrj   r   r   )r7   r   r9   rM   rM   rN   rz   d  s   

z,DocstringParameterChecker._add_raise_messagerP   )+__name__
__module____qualname____doc__r   __implements__rB   msgslistr   DOCSTRING_TYPESoptionspriorityrQ   r   r   rt   rO   visit_asyncfunctiondefrF   rG   rH   Raiser   rf   r   Yieldr   	YieldFromr   r   r   r   r   re   	ArgumentsNodeNGr   boolrV   rS   rx   rz   rM   rM   rM   rN   r
   *   s    S8
	$'$
 r
   c                 C   s   |  t|  dS )zRequired method to auto register this checker.

    :param linter: Main interface object for Pylint plugins
    :type linter: Pylint object
    N)register_checkerr
   )linterrM   rM   rN   register|  s   r   )r   r@   typingr   re   r   pylint.checkersr   r   rC   pylint.extensionsr   #pylint.extensions._check_docs_utilsr   pylint.interfacesr   pylint.utilsr	   r
   r   rM   rM   rM   rN   <module>   s"       V