o
    h                     @  sd   d 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ZG dd	 d	eZ	G d
d dZ
dS )z&Statistic collection logic for Flake8.    )annotations)	Generator)
NamedTuple)	Violationc                   @  s<   e Zd ZdZdddZdddZdddZ	ddddZdS )
Statisticsz5Manager of aggregated statistics for a run of Flake8.returnNonec                 C  s
   i | _ dS )z8Initialize the underlying dictionary for our statistics.N)_storeself r   G/var/www/html/ai/venv/lib/python3.10/site-packages/flake8/statistics.py__init__   s   
zStatistics.__init__	list[str]c                 C  s   t dd | jD S )ziReturn all unique error codes stored.

        :returns:
            Sorted list of error codes.
        c                 S  s   h | ]}|j qS r   )code.0keyr   r   r   	<setcomp>   s    z)Statistics.error_codes.<locals>.<setcomp>sortedr	   r
   r   r   r   error_codes   s   zStatistics.error_codeserrorr   c                 C  s6   t |}|| jvrt|| j|< | j|   dS )zAdd the fact that the error was seen in the file.

        :param error:
            The Violation instance containing the information about the
            violation.
        N)Keycreate_fromr	   	Statistic	increment)r   r   r   r   r   r   record   s   

zStatistics.recordNprefixstrfilename
str | None Generator[Statistic, None, None]c                 #  s6    t  fdd| jD }|D ]}| j| V  qdS )aB  Generate statistics for the prefix and filename.

        If you have a :class:`Statistics` object that has recorded errors,
        you can generate the statistics for a prefix (e.g., ``E``, ``E1``,
        ``W50``, ``W503``) with the optional filter of a filename as well.

        .. code-block:: python

            >>> stats = Statistics()
            >>> stats.statistics_for('E12',
                                     filename='src/flake8/statistics.py')
            <generator ...>
            >>> stats.statistics_for('W')
            <generator ...>

        :param prefix:
            The error class or specific error code to find statistics for.
        :param filename:
            (Optional) The filename to further filter results by.
        :returns:
            Generator of instances of :class:`Statistic`
        c                 3  s     | ]}|  r|V  qd S N)matchesr   r    r   r   r   	<genexpr>>   s    
z,Statistics.statistics_for.<locals>.<genexpr>Nr   )r   r   r    matching_errors
error_coder   r%   r   statistics_for%   s   zStatistics.statistics_forr   r   )r   r   )r   r   r   r   r#   )r   r   r    r!   r   r"   )__name__
__module____qualname____doc__r   r   r   r)   r   r   r   r   r   
   s    


r   c                   @  s:   e Zd ZU dZded< ded< eddd	ZdddZdS )r   zSimple key structure for the Statistics dictionary.

    To make things clearer, easier to read, and more understandable, we use a
    namedtuple here for all Keys in the underlying dictionary for the
    Statistics object.
    r   r    r   r   r   r   c                 C  s   | |j |jdS )z6Create a Key from :class:`flake8.violation.Violation`.r    r   r/   clsr   r   r   r   r   P   s   zKey.create_fromr   r!   boolc                 C  s   | j |o|du p| j|kS )a  Determine if this key matches some constraints.

        :param prefix:
            The error code prefix that this key's error code should start with.
        :param filename:
            The filename that we potentially want to match on. This can be
            None to only match on error prefix.
        :returns:
            True if the Key's code starts with the prefix and either filename
            is None, or the Key's filename matches the value passed in.
        N)r   
startswithr    )r   r   r    r   r   r   r$   U   s   zKey.matchesN)r   r   r   r   )r   r   r    r!   r   r2   )r+   r,   r-   r.   __annotations__classmethodr   r$   r   r   r   r   r   E   s   
 r   c                   @  s2   e Zd ZdZdd
dZedddZdddZdS )r   zSimple wrapper around the logic of each statistic.

    Instead of maintaining a simple but potentially hard to reason about
    tuple, we create a class which has attributes and a couple
    convenience methods on it.
    r(   r   r    messagecountintr   r   c                 C  s   || _ || _|| _|| _dS )zInitialize our Statistic.Nr(   r    r6   r7   )r   r(   r    r6   r7   r   r   r   r   n   s   
zStatistic.__init__r   r   c                 C  s   | |j |j|jddS )z>Create a Statistic from a :class:`flake8.violation.Violation`.r   r9   )r   r    textr0   r   r   r   r   w   s   zStatistic.create_fromc                 C  s   |  j d7  _ dS )zAIncrement the number of times we've seen this error in this file.   N)r7   r
   r   r   r   r      s   zStatistic.incrementN)
r(   r   r    r   r6   r   r7   r8   r   r   )r   r   r   r   r*   )r+   r,   r-   r.   r   r5   r   r   r   r   r   r   r   f   s    
		r   N)r.   
__future__r   typingr   r   flake8.violationr   r   r   r   r   r   r   r   <module>   s    ;!