Your IP : 216.73.216.196


Current Path : /opt/alt/python37/lib/python3.7/site-packages/pydocstyle/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/pydocstyle/__pycache__/checker.cpython-37.pyc

B

;��Yks�@s&dZddlZddlZddlZddlZddlmZddlm	Zddl
mZddlm
Z
ddlmZdd	lmZmZmZmZmZmZmZmZmZmZmZmZdd
lmZmZm Z ddl!m"Z"m#Z#m$Z$dZ%y
ej&Z'Wne(k
r�e&Z'YnXddd�Z)Gdd�de*�Z+e�Z,ddd�Z-dd�Z.dd�Z/dS)z5Parsed source code checkers for docstring violations.�N)�	takewhile)�compile)�
namedtuple�)�
violations)�IllegalConfiguration)�Package�Module�Class�NestedClass�
Definition�AllError�Method�Function�NestedFunction�Parser�StringIO�
ParseError)�log�is_blank�pairwise)�IMPERATIVE_VERBS�IMPERATIVE_BLACKLIST�stem)�checkFcs��fdd�}|S)Ncs�|_�|_|S)N)�
_check_for�	_terminal)�f)�kind�terminal��C/opt/alt/python37/lib/python3.7/site-packages/pydocstyle/checker.py�	decorator szcheck_for.<locals>.decoratorr )rrr"r )rrr!�	check_forsr#c
@s�eZdZdZdddddddd	d
ddd
dg
ZdDdd�Zedd��Zee	dd�dd��Z
ee	�dd��Zee�dd��Z
ee�dd��Zee	�dd��Zed d!��Zee	�d"d#��Zee	�d$d%��Zee	�d&d'��Zee	�d(d)��Zee	�d*d+��Zee	�d,d-��Zee	�d.d/��Zee	�d0d1��Zee�d2d3��Zee�d4d5��Zee�d6d7��Zee	�d8d9��Zed:d;��Zed<d=��Z e!d>d?��Z"e!d@dA��Z#ee	�dBdC��Z$dS)E�ConventionCheckerz�Checker for PEP 257 and numpy conventions.

    D10x: Missing docstrings
    D20x: Whitespace issues
    D30x: Docstring formatting
    D40x: Docstring content issues

    z
Short SummaryzExtended SummaryZ
ParametersZReturnsZYieldszOther ParametersZRaiseszSee AlsoZNotes�
ReferencesZExamplesZ
AttributesZMethodsNc#s�tt|�|�}x�|D]�}x�|jD]�}d}t||j�r�|jdk}�dk	o\t�fdd�|jD��}	|sv|	sv||||j�}
nd}
t	|
d�r�|
n|
g}xV|D]N}
|
dk	r�|
j
|jkr�|j�d�}|\}
}}|
j
||d�|
V|jr�d}Pq�W|r Pq WqWdS)	NF�allc3s"|]}t��|j��dkVqdS)rN)�len�findall�name)�.0�dec)�ignore_decoratorsr r!�	<genexpr>Gsz1ConventionChecker.check_source.<locals>.<genexpr>�__iter__z.
)�explanation�
definitionT)�parser�checks�
isinstancerZskipped_error_codes�anyZ
decorators�	docstring�hasattr�code�__doc__�	partitionZset_contextr)�self�source�filenamer,�moduler0�
this_check�	terminateZskipping_allZdecorator_skip�error�errorsr9�message�_r/r )r,r!�check_source?s6






zConventionChecker.check_sourcecCs*dd�tt|����D�}t|dd�d�S)NcSsg|]}t|d�r|�qS)r)r6)r*r>r r r!�
<listcomp>_sz,ConventionChecker.checks.<locals>.<listcomp>cSs|jS)N)r)r>r r r!�<lambda>a�z*ConventionChecker.checks.<locals>.<lambda>)�key)�vars�type�values�sorted)r:r&r r r!r2]szConventionChecker.checksT)rcsb|s
�js|r^tt�|��r^ttjttjt	tj
t�fdd�ttj
ttj
ttji}|t���SdS)a�D10{0,1,2,3}: Public definitions should have docstrings.

        All modules should normally have docstrings.  [...] all functions and
        classes exported by a module should also have docstrings. Public
        methods (including the __init__ constructor) should also have
        docstrings.

        Note: Public (exported) definitions are either those with names listed
              in __all__ variable (if present), or those that do not start
              with a single underscore.

        cs$�jrt��S�jrt��St��S)N)Zis_magicrZD105Zis_initZD107ZD102r )r0r r!rFvsz;ConventionChecker.check_docstring_missing.<locals>.<lambda>N)Z	is_publicr�ast�literal_evalr	rZD100r
ZD101rZD106rrZD103rrZD104rJ)r:r0r5�codesr )r0r!�check_docstring_missingcs

z)ConventionChecker.check_docstring_missingcCsL|rHt�|��d�}t|�dkrHtdd�|D��}|dkrHt�t|��SdS)z�D200: One-liner docstrings should fit on one line with quotes.

        The closing quotes are on the same line as the opening quotes.
        This looks better for one-liners.

        �
rcss|]}t|�sdVqdS)rN)r)r*�lr r r!r-�sz5ConventionChecker.check_one_liners.<locals>.<genexpr>N)rMrN�splitr'�sumrZD200)r:r0r5�lines�non_empty_linesr r r!�check_one_liners~sz"ConventionChecker.check_one_linersc
cs�|r�|j�|�\}}}ttt|�d�dd���}ttt|�d�dd���}tttt	|���}ttt|��}	|dkr�t
�|�Vt|�s�|	dkr�t
�
|	�VdS)z�D20{1,2}: No blank lines allowed around function/method docstring.

        There's no blank line either before or after the docstring.

        rQN���rr)r;r9�list�maprrSrTr�bool�reversedrZD201r&ZD202)
r:�functionr5�beforerC�after�
blanks_before�blanks_after�blanks_before_count�blanks_after_countr r r!�check_no_blank_before�sz'ConventionChecker.check_no_blank_beforec
cs�|r�|j�|�\}}}ttt|�d�dd���}ttt|�d�dd���}tttt	|���}ttt|��}	|dkr�t
�|�V|dkr�t
�|�Vt
|�s�|	dkr�t
�|	�VdS)a�D20{3,4}: Class docstring should have 1 blank line around them.

        Insert a blank line before and after all docstrings (one-line or
        multi-line) that document a class -- generally speaking, the class's
        methods are separated from each other by a single blank line, and the
        docstring needs to be offset from the first method by a blank line;
        for symmetry, put a blank line between the class header and the
        docstring.

        rQNrXrr)r;r9rYrZrrSrTrr[r\rZD211ZD203r&ZD204)
r:�class_r5r^rCr_r`rarbrcr r r!�check_blank_before_after_class�sz0ConventionChecker.check_blank_before_after_classcCs^|rZt�|����d�}t|�dkrZttt|dd���}tt	t
|��}|dkrZt�|�SdS)a�D205: Put one blank line between summary line and description.

        Multi-line docstrings consist of a summary line just like a one-line
        docstring, followed by a blank line, followed by a more elaborate
        description. The summary line may be used by automatic indexing tools;
        it is important that it fits on one line and is separated from the
        rest of the docstring by a blank line.

        rQrN)
rMrN�striprSr'rYrZrrTrr[rZD205)r:r0r5rUZpost_summary_blanksZblanks_countr r r!�check_blank_after_summary�sz+ConventionChecker.check_blank_after_summarycCs&|j�|�\}}}|�d�\}}}|S)z9Return the indentation of the docstring's opening quotes.rQ)r;r9�
rpartition)r0r5Zbefore_docstringrC�indentr r r!�_get_docstring_indent�sz'ConventionChecker._get_docstring_indentccs�|r�|�||�}|�d�}t|�dkr�|dd�}dd�|D�}td�td�|�|�krdt��Vt|�dkr�t|dd��|ks�|d|kr�t��Vt|�|kr�t�	�VdS)	z�D20{6,7,8}: The entire docstring should be indented same as code.

        The entire docstring is indented the same as the quotes at its
        first line.

        rQrNcSsg|]}t|�st|��qSr )r�
leading_space)r*rRr r r!rE�sz2ConventionChecker.check_indent.<locals>.<listcomp>z 	�rX)
rkrSr'�set�joinrZD206�minZD208ZD207)r:r0r5rjrU�indentsr r r!�check_indent�s

 
zConventionChecker.check_indentcCsL|rHdd�t�|��d�D�}t|�dkrH|�d�d��dkrHt��SdS)z�D209: Put multi-line docstring closing quotes on separate line.

        Unless the entire docstring fits on a line, place the closing
        quotes on a line by themselves.

        cSsg|]}t|�s|�qSr )r)r*rRr r r!rE�szHConventionChecker.check_newline_after_last_paragraph.<locals>.<listcomp>rQrrX)z"""z'''N)rMrNrSr'rgrZD209)r:r0r5rUr r r!�"check_newline_after_last_paragraph�s
z4ConventionChecker.check_newline_after_last_paragraphcCsH|rDt�|��d�}|d�d�s<t|�dkrD|d�d�rDt��SdS)z8D210: No whitespaces allowed surrounding docstring text.rQr� rN)rMrNrS�
startswithr'�endswithrZD210)r:r0r5rUr r r!�check_surrounding_whitespaces�s
z/ConventionChecker.check_surrounding_whitespacescCsf|rbddddddddg}t�|��d	�}t|�d
krb|�d	�d����}||krZt��St��SdS)
z�D21{2,3}: Multi-line docstring summary style check.

        A multi-line docstring summary should start either at the first,
        or separately at the second line of a docstring.

        z"""z'''zu"""zu'''zr"""zr'''zur"""zur'''rQrrN)	rMrNrSr'rg�lowerrZD212ZD213)r:r0r5Zstart_triplerU�firstr r r!�check_multi_line_summary_startsz0ConventionChecker.check_multi_line_summary_startcCsT|rPdt�|�krtd�}ntd�}|�|�sPtd�}|�|��d�}t�|�SdS)a�D300: Use """triple double quotes""".

        For consistency, always use """triple double quotes""" around
        docstrings. Use r"""raw triple double quotes""" if you use any
        backslashes in your docstrings. For Unicode docstrings, use
        u"""Unicode triple-quoted strings""".

        Note: Exception to this is made if the docstring contains
              """ quotes in its body.

        z"""z[uU]?[rR]?'''[^'].*z[uU]?[rR]?"""[^"].*z[uU]?[rR]?("+|'+).*rN)rMrN�re�match�grouprZD300)r:r0r5ZregexZillegal_matcherZillegal_quotesr r r!�check_triple_double_quotes s


z,ConventionChecker.check_triple_double_quotescCs"|rd|kr|�d�st��SdS)z�D301: Use r""" if any backslashes in a docstring.

        Use r"""raw triple double quotes""" if you use any backslashes
        (\) in your docstrings.

        �\)�r�urN)rurZD301)r:r0r5r r r!�check_backslashes;s
z#ConventionChecker.check_backslashescCs@d|jjkrdS|r<tjddkr<t|�s<|�d�s<t��SdS)z�D302: Use u""" for docstrings with Unicode.

        For Unicode docstrings, use u"""Unicode triple-quoted strings""".

        �unicode_literalsNr�)�ur�)r=Zfuture_imports�sys�version_info�is_asciirurZD302)r:r0r5r r r!�check_unicode_docstringIsz)ConventionChecker.check_unicode_docstringcCs8|r4t�|����d�d}|�d�s4t�|d�SdS)z}D400: First line should end with a period.

        The [first line of a] docstring is a phrase ending in a period.

        rQr�.rXN)rMrNrgrSrvrZD400)r:r0r5Zsummary_liner r r!�check_ends_with_periodZs
z(ConventionChecker.check_ends_with_periodcCs�|r�|js�t�|���}|r�|��d}|��}|tkrBt�|�Syt	�
t|��}Wntk
rhdSX|r�||kr�t�
|��|�SdS)aD401: First line should be in imperative mood: 'Do', not 'Does'.

        [Docstring] prescribes the function or method's effect as a command:
        ("Do this", "Return that"), not as a description; e.g. don't write
        "Returns the pathname ...".

        rN)Zis_testrMrNrgrSrxrrZD401br�getr�UnicodeDecodeErrorZD401�
capitalize)r:r]r5�stripped�
first_wordZ
check_wordZcorrect_formr r r!�check_imperative_moodfs	

z'ConventionChecker.check_imperative_moodcCs>|r:t�|����d�d}|jd|�dd�kr:t��SdS)z�D402: First line should not be function's or method's "signature".

        The one-line docstring should NOT be a "signature" reiterating the
        function/method parameters (which can be obtained by introspection).

        rQr�(rtrmN)rMrNrgrSr)�replacerZD402)r:r]r5�
first_liner r r!�check_no_signature�sz$ConventionChecker.check_no_signaturecCsj|rft�|���d}||��kr&dSx"|D]}|tjkr,|dkr,dSq,W||��krft�|��|�SdS)z�D403: First word of the first line should be properly capitalized.

        The [first line of a] docstring is a phrase ending in a period.

        rN�')	rMrNrS�upper�string�
ascii_lettersr�rZD403)r:r]r5r��charr r r!�check_capitalized�s
z#ConventionChecker.check_capitalizedcCs.|r*t�|���d}|��dkr*t��SdS)z�D404: First word of the docstring should not be `This`.

        Docstrings should use short, simple language. They should not begin
        with "This class is [..]" or "This module contains [..]".

        r�thisN)rMrNrSrxrZD404)r:r]r5r�r r r!�check_starts_with_this�sz(ConventionChecker.check_starts_with_thiscCs&td��|���}|dk	r"|��SdS)z�Return any leading set of words from `line`.

        For example, if `line` is "  Hello world!!!", returns "Hello world".
        z
[A-Za-z ]+N)r{r|rgr})�line�resultr r r!�_get_leading_words�sz$ConventionChecker._get_leading_wordsc	sT�j��j���}ddddddddd	g	}t�fd
d�|D��}t|�pR|pRt�j�S)a`Check if the suspected context is really a section header.

        Lets have a look at the following example docstring:
            '''Title.

            Some part of the docstring that specifies what the function
            returns. <----- Not a real section name. It has a suffix and the
                            previous line is not empty and does not end with
                            a punctuation sign.

            This is another line in the docstring. It describes stuff,
            but we forgot to add a blank line between it and the section name.
            Returns  <----- A real section name. The previous line ends with
            -------         a period, therefore it is in a new
                            grammatical context.
            Bla.

            '''

        To make sure this is really a section we check these conditions:
            * There's no suffix to the section name.
            * The previous line ends with punctuation.
            * The previous line is empty.

        If one of the conditions is true, we will consider the line as
        a section name.
        �,�;r��-r�/�]�}�)c3s|]}�j���|�VqdS)N)�
previous_linergrv)r*�x)�contextr r!r-�sz<ConventionChecker._is_a_docstring_section.<locals>.<genexpr>)r��lstrip�section_namergr4rr�)r�Zsection_name_suffix�punctuationZprev_line_ends_with_punctuationr )r�r!�_is_a_docstring_section�sz)ConventionChecker._is_a_docstring_sectionccsNd}x0|jD]}t|�sP|d7}qWt�|�VdS|j|}d�t|����dk}|s|t�|�V|dkrzt�|�Vn�|dkr�t�|�V|��dt	|�kr�t�
t	|�|t	|����Vt|�|kr�t�|�V|d}|t	|j�k�r>|j|}	t|	��rJ|j|d�}
td�|
���s0t�|�Vnt�
|�Vnt�
|�VdS)a+D4{07,08,09,12}, D215: Section underline checks.

        Check for correct formatting for docstring sections. Checks that:
            * The line that follows the section name contains
              dashes (D40{7,8}).
            * The amount of dashes is equal to the length of the section
              name (D409).
            * The section's content does not begin in the line that follows
              the section header (D412).
            * The indentation of the dashed line is equal to the docstring's
              indentation (D215).
        rrNrmr�)�following_linesrrZD407rornrgZD412ZD408r'ZD409rlZD215ZD414)�clsr�r��indentationZblank_lines_after_headerr�Znon_empty_lineZdash_line_foundZline_after_dashes_indexZline_after_dashesZ
rest_of_linesr r r!�_check_section_underline�s<



z*ConventionChecker._check_section_underlineccs�|j��}|�||�}|j|jkr<||jkr<t�||j�Vt|j�|krVt�|�V|j�	��
|j�}|r�t�||j�	��V|jr�t
|jd�s�|jr�t�|�Vnt�|�Vt
|j�s�t�|�Vx|�|||�D]
}|Vq�WdS)a�D4{05,06,10,11,13}, D214: Section name checks.

        Check for valid section names. Checks that:
            * The section name is properly capitalized (D405).
            * The section is not over-indented (D214).
            * The section name has no superfluous suffix to it (D406).
            * There's a blank line after the section (D410, D413).
            * There's a blank line before the section (D411).

        Also yields all the errors from `_check_section_underline`.
        rXN)r��titlerk�
SECTION_NAMESrZD405rlr�ZD214rgr�ZD406r�r�is_last_sectionZD413ZD410r�ZD411r�)r�r5r0r�Zcapitalized_sectionr��suffix�errr r r!�_check_sections*



z ConventionChecker._check_sectionc
	#s|sdS|�d��t��dkr"dSdd��jD����fdd���fdd�t��D�}td	d
�����fdd�|D�}�fd
d�|D�}xrt|d�D]d\}}|dkr�dn|j}�|j|j|j	�|jd|�|j|dk�}x��
|||�D]
}	|	Vq�Wq�WdS)axD21{4,5}, D4{05,06,07,08,09,10}: Docstring sections checks.

        Check the general format of a sectioned docstring:
            '''This is my one-liner.

            Short Summary
            -------------
            This is my summary.

            Returns
            -------
            None.

            '''

        Section names appear in `SECTION_NAMES`.
        NrQr�cSsg|]}|���qSr )rx)r*�sr r r!rEbsz>ConventionChecker.check_docstring_sections.<locals>.<listcomp>cs��|���}|�kS)N)r�rx)�_liner�)�lower_section_namesr:r r!�_suspected_as_sectiondszIConventionChecker.check_docstring_sections.<locals>._suspected_as_sectioncsg|]\}}�|�r|�qSr r )r*�ir�)r�r r!rEis�SectionContext)r�r�r�r��original_indexr�c3sF|]>}����|����|d�|�|dd�|d�VqdS)rNF)r�rg)r*r�)r�rUr:r r!r-usz=ConventionChecker.check_docstring_sections.<locals>.<genexpr>c3s|]}��|�r|VqdS)N)r�)r*�c)r:r r!r-~srXr)rSr'r��	enumeraterrr�r�r�r�r�)
r:r0r5Zsuspected_section_indicesZcontexts�a�b�endZnew_ctxr�r )r�r�rUr�r:r!�check_docstring_sectionsHs,

	
z*ConventionChecker.check_docstring_sections)N)%�__name__�
__module__�__qualname__r8r�rD�propertyr2r#rrPrWrrdr
rfrh�staticmethodrkrrrsrwrzr~r�r�r�r�r�r�r�r�r��classmethodr�r�r�r r r r!r$'sN
!	 


'<*r$c
cs(|dk	r|dk	rtd��n:|dk	r(|}n,|dk	rLtttj���t|��}ntjj}x�|D]�}t�	d|�yTt
|��}|��}WdQRXx2t��
|||�D]}t|dd�}	|	|kr�|Vq�WWqZtttfk
r�}zt�d||�|VWdd}~XYqZtjk
�rtd|�VYqZXqZWdS)a0Generate docstring errors that exist in `filenames` iterable.

    By default, the PEP-257 convention is checked. To specifically define the
    set of error codes to check for, supply either `select` or `ignore` (but
    not both). In either case, the parameter should be a collection of error
    code strings, e.g., {'D100', 'D404'}.

    When supplying `select`, only specified error codes will be reported.
    When supplying `ignore`, all error codes which were not specified will be
    reported.

    Note that ignored error code refer to the entire set of possible
    error codes, which is larger than just the PEP-257 convention. To your
    convenience, you may use `pydocstyle.violations.conventions.pep257` as
    a base set to add or remove errors from.

    Examples
    ---------
    >>> check(['pydocstyle.py'])
    <generator object check at 0x...>

    >>> check(['pydocstyle.py'], select=['D100'])
    <generator object check at 0x...>

    >>> check(['pydocstyle.py'], ignore=conventions.pep257 - {'D100'})
    <generator object check at 0x...>

    Nz@Cannot pass both select and ignore. They are mutually exclusive.zChecking file %s.r7zError in file %s: %szinvalid syntax in file %s)rrYrnrZ
ErrorRegistryZget_error_codesZconventionsZpep257r�info�
tokenize_open�readr$rD�getattr�EnvironmentErrorr
rZwarning�tk�
TokenError�SyntaxError)
�	filenames�select�ignorer,Z
checked_codesr<�filer;r@r7r r r!r�s.



rcCstdd�|D��S)Ncss|]}t|�dkVqdS)�N)�ord)r*r�r r r!r-�szis_ascii.<locals>.<genexpr>)r&)r�r r r!r��sr�cCstd��|���S)Nz\s*)r{r|r})r�r r r!rl�srl)F)NNN)0r8rMr�r��tokenizer��	itertoolsrr{r�collectionsrrmr�configr�parserrr	r
rrr
rrrrrr�utilsrrrZ	wordlistsrrr�__all__�openr��AttributeErrorr#�objectr$r1rr�rlr r r r!�<module>s68


k
9