
    yIf                        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          Z G d d	e          Z	 G d
 d          Z
dS )z&Statistic collection logic for Flake8.    )annotations)	Generator)
NamedTuple)	Violationc                  6    e Zd ZdZddZddZdd	Z	 dddZd
S )
Statisticsz5Manager of aggregated statistics for a run of Flake8.returnNonec                    i | _         dS )z8Initialize the underlying dictionary for our statistics.N)_storeselfs    E/var/www/piapp/venv/lib/python3.11/site-packages/flake8/statistics.py__init__zStatistics.__init__   s    ,.    	list[str]c                >    t          d | j        D                       S )ziReturn all unique error codes stored.

        :returns:
            Sorted list of error codes.
        c                    h | ]	}|j         
S  )code).0keys     r   	<setcomp>z)Statistics.error_codes.<locals>.<setcomp>   s    777Csx777r   sortedr   r   s    r   error_codeszStatistics.error_codes   s#     774;777888r   errorr   c                    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   s      r   recordzStatistics.record   s[     ooe$$dk!!(44U;;DKC""$$$$$r   Nprefixstrfilename
str | None Generator[Statistic, None, None]c              #  x   K   t          fd| j        D                       }|D ]}| j        |         V  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  H   K   | ]}|                               |V  d S N)matches)r   r   r&   r$   s     r   	<genexpr>z,Statistics.statistics_for.<locals>.<genexpr>>   sJ       !
 !
#++fh*G*G!
!
 !
 !
 !
 !
 !
r   Nr   )r   r$   r&   matching_errors
error_codes    ``  r   statistics_forzStatistics.statistics_for%   sw      2 ! !
 !
 !
 !
 !
;!
 !
 !
 
 
 * 	* 	*J+j)))))	* 	*r   r	   r
   )r	   r   )r   r   r	   r
   r+   )r$   r%   r&   r'   r	   r(   )__name__
__module____qualname____doc__r   r   r#   r0   r   r   r   r   r   
   st        ??/ / / /9 9 9 9
% 
% 
% 
% 37* * * * * * *r   r   c                  H    e Zd ZU dZded<   ded<   edd            Z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                0     | |j         |j                  S )z6Create a Key from :class:`flake8.violation.Violation`.r&   r   r8   clsr   s     r   r    zKey.create_fromP   s     sEN<<<<r   r$   r'   boolc                T    | 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&   s      r   r,   zKey.matchesU   s5     y##F++ 
9 9	
r   N)r   r   r	   r   )r$   r%   r&   r'   r	   r;   )r2   r3   r4   r5   __annotations__classmethodr    r,   r   r   r   r   r   E   sf           MMMIII= = = [=
 
 
 
 
 
r   r   c                  :    e Zd ZdZdd
Zedd            Z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                >    || _         || _        || _        || _        dS )zInitialize our Statistic.Nr/   r&   rA   rB   )r   r/   r&   rA   rB   s        r   r   zStatistic.__init__n   s$     % 


r   r   r   c                >     | |j         |j        |j        d          S )z>Create a Statistic from a :class:`flake8.violation.Violation`.r   rE   )r   r&   textr9   s     r   r    zStatistic.create_fromw   s/     sz^J	
 
 
 	
r   c                &    | xj         dz  c_         dS )zAIncrement the number of times we've seen this error in this file.   N)rB   r   s    r   r"   zStatistic.increment   s    

a



r   N)
r/   r%   r&   r%   rA   r%   rB   rC   r	   r
   )r   r   r	   r!   r1   )r2   r3   r4   r5   r   r?   r    r"   r   r   r   r!   r!   f   sf             
 
 
 [
     r   r!   N)r5   
__future__r   typingr   r   flake8.violationr   r   r   r!   r   r   r   <module>rM      s    , , " " " " " "             & & & & & &8* 8* 8* 8* 8* 8* 8* 8*v
 
 
 
 
* 
 
 
B         r   