
    c                       U d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlmZ d dlmZmZ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Zd d
lmZ d dlmZmZmZm Z  d dl!m"Z" d dl#m$Z$ d dl%m&Z&m'Z'm(Z(m)Z) d dl*m+Z+ d dl,m-Z- d dl.m/Z/m0Z0 d dl1m2Z2m3Z3 d dl4m5Z5 d dl6m7Z7 d dl8m9Z9m:Z:m;Z; d dl<m=Z=m>Z>m?Z?m@Z@ d dlAmBZBmCZCmDZD d dlEmFZF d dlGmHZH d d
lImZJ d dlKmLZLmMZMmNZNmOZOmPZPmQZQmRZR d dlSmTZTmUZUmVZVmWZW ejX        dk    rd dlmYZY nd dlZmYZY ej[        Z[ G d deY          Z\dvd"Z]dwd%Z^i d&d'd(d)d*e)j_        ifd+d,d-d.d*e)j_        ifd/d0d1d2d*e)j_        ifd3d4d5d6d*e)j_        ifd7d8d9d:d*e)j_        ifd;d<d=d>d*e)j_        ifd?d@dAdBd*e)j_        ifdCdDdEdFd*e)j_        ifdGdHdIdJd*e)j_        ifdKdLdMdNd*e)j_        ifdOdPdQdRdSge)j_        dTfdUd'dVdWd*e)j_        ifdXdYdZd[d*e)j_        ifd\d]d^d_e)j_        d`gdafdbdcdddee)j_        d`gdafdfdgdhdid*e)j_        ifdjdkdldmd*e)j_        ifdndodpdqd*e)j_        ifiZ`dreads<    G dt due$e5e jb        ej"                  ZcdS )x    )annotationsN)defaultdict)CallableIteratorSequence)TextIOWrapper)Path)Pattern)
ModuleType)Any)nodes)checkers
exceptions
interfaces	reporters)BaseChecker)_ArgumentsManager)MAIN_CHECKER_NAME	MSG_TYPESMSG_TYPES_STATUSWarningScope)HIGH)_make_linter_options)load_resultssave_results)_is_ignored_fileexpand_modules)_MessageStateHandler)check_parallel)report_messages_by_module_statsreport_messages_statsreport_total_messages_stats)_is_relative_tofix_import_pathget_fatal_error_messageprepare_crash_report)MessageMessageDefinitionMessageDefinitionStore)BaseReporter)TextReporter)DirectoryNamespaceDictFileItemManagedMessageMessageDefinitionTupleMessageLocationTupleModuleDescriptionDictOptions)	ASTWalker	FileStateLinterStatsutils)      )Protocolc                      e Zd Z	 d
dd	ZdS )GetAstProtocolNfilepathstrmodnamedata
str | Nonereturnnodes.Modulec                    d S N )selfr<   r>   r?   s       4lib/python3.11/site-packages/pylint/lint/pylinter.py__call__zGetAstProtocol.__call__N   s	     	    rD   )r<   r=   r>   r=   r?   r@   rA   rB   )__name__
__module____qualname__rH   rE   rI   rG   r;   r;   M   s0        >B      rI   r;   rA   r=   c                     t          t          j        t                    sJ t          t          j                                        d          t          _        t          j                                        S )Nutf-8encoding)
isinstancesysstdinr   detachreadrE   rI   rG   _read_stdinrV   T   sN    ci/////ci..007CCCCI9>>rI   reporter_classtype[BaseReporter]c                    | }t           j                            |          }t           j                            |          }|                    d          d         }t          ||          }t          |t                    sJ | d            |S )N.z is not a BaseReporter)astroidmodutilsget_module_partload_module_from_namesplitgetattr
issubclassr*   )rW   qnamemodule_partmodule
class_nameklasss         rG   _load_reporter_by_classrh   [   s    E"22599K33K@@FS!!"%JFJ''Ee\**LLu,L,L,LLLLLrI   F0001z%sfatalzoUsed when an error occurred preventing the analysis of a               module (unable to find it for instance).scopeF0002z%s: %sastroid-errorzUsed when an unexpected error occurred while building the Astroid  representation. This is usually accompanied by a traceback. Please report such errors !F0010zerror while code parsing: %sparse-errorzlUsed when an exception occurred while building the Astroid representation which could be handled by astroid.F0011z)error while parsing the configuration: %szconfig-parse-errorzJUsed when an exception occurred while parsing a pylint configuration file.I0001z0Unable to run raw checkers on built-in module %sraw-checker-failedzRUsed to inform that a built-in module has not been checked using the raw checkers.I0010z#Unable to consider inline option %rzbad-inline-optionzUUsed when an inline option is either badly formatted or can't be used inside modules.I0011zLocally disabling %s (%s)zlocally-disabledzEUsed when an inline option disables a message or a messages category.I0013zIgnoring entire filezfile-ignoredz0Used to inform that the file will not be checkedI0020zSuppressed %s (from line %d)zsuppressed-messagezA message was triggered on a line, but suppressed explicitly by a disable= comment in the file. This message is not generated for messages that are ignored due to configuration settings.I0021zUseless suppression of %szuseless-suppressionzbReported when a message is explicitly disabled for a line or a block of code, but never triggered.I0022z+Pragma "%s" is deprecated, use "%s" insteadzdeprecated-pragmazSome inline pylint options have been renamed or reworked, only the most recent form should be used. NOTE:skip-all is only available with pylint >= 0.26)I0014zdeprecated-disable-all)	old_namesrk   E0001syntax-errorz0Used when a syntax error is raised for a module.E0011zUnrecognized file option %rzunrecognized-inline-optionz2Used when an unknown inline option is encountered.W0012zKUnknown option value for '%s', expected a valid pylint message and got '%s'zunknown-option-valuez8Used when an unknown value is encountered for an option.)E0012zbad-option-value)rk   rz   R0022z!Useless option value for '%s', %szuseless-option-valuezOUsed when a value for an option that is now deleted from pylint is encountered.E0013z;Plugin '%s' is impossible to load, is it installed ? ('%s')bad-plugin-valuez0Used when a bad value is used in 'load-plugins'.E0014zOOut-of-place setting encountered in top level configuration-section '%s' : '%s'zbad-configuration-sectionz_Used when we detect a setting in the top level of a toml configuration that shouldn't be there.E0015zUnrecognized option found: %szunrecognized-optionz7Used when we detect an option that we do not recognize.z!dict[str, MessageDefinitionTuple]MSGSc                  $   e Zd ZU dZeZeZdZde	d<   dddZ
	 	 	 	 dddZedd            Zej        dd            ZddZddZddZddZdd!Zdd#Zdd&Zdd(Zdd+Zdd,Zdd.Zdd/Zdd0Zdd1Zdd2Zdd3Zeddd8            Z dd9Z!dd=Z"dd?Z#ddDZ$ddGZ%ddJZ&ddNZ'ddQZ(ddTZ)ddUZ*ddVZ+ddYZ,	 dddZZ-dd_Z.e/j0        dda            Z1	 dddcZ2ddlZ3ddnZ4ddoZ5ddqZ6ddrZ7dd~Z8	 	 	 	 	 	 	 dddZ9d	e:j;        fddZ<ddZ=d	S )PyLintera  Lint Python modules using external checkers.

    This is the main checker controlling the other ones and the reports
    generation. It is itself both a raw checker and an astroid checker in order
    to:
    * handle message activation / deactivation at the module level
    * handle some basic but necessary stats' data (number of classes, methods...)

    IDE plugin developers: you may have to call
    `astroid.MANAGER.clear_cache()` across runs if you want
    to ensure the latest code version is actually checked.

    This class needs to support pickling for parallel linting to work. The exception
    is reporter member; see check_parallel function for more details.
    z"pylint-crash-%Y-%m-%d-%H-%M-%S.txtr=   crash_file_path%Options controlling analysis messages2Options related to output formatting and reporting)Messages controlReportsrE   Noptionsr2   reporter7reporters.BaseReporter | reporters.MultiReporter | Noneoption_groupstuple[tuple[str, str], ...]pylintrcr@   rA   Nonec                   t          j        | d           t          j        | |            |  |r|                     |           n!|                     t	                                 i | _        	 t          j        t                    | _	        	 i | _
        	 t                      | _        |t          |           z   | _        |D ]}|d         | j        |d         <   |dz   | _        g | _        	 d| _        t&          j                            |            t*          j                            | |            ddt.          fd	d
t0          fddt2          ff| _        t7          | j        j                  | _        d| _        g | _         tC          d| j        d          | _"        d | _#        d | _$        d| _%        g | _&        | '                    |            d S )Npylint)prog   r   ))r   r   )r   r   FRP0001zMessages by categoryRP0002z% errors / warnings by moduleRP0003Messages T)is_base_filestate)(r   __init__r   set_reporterr+   
_reporterscollectionsr   list	_checkers_dynamic_pluginsr5   statsr   r   option_groups_descs_option_groupsfail_on_symbols_error_moder   ReportsHandlerMixInr   r   r"   r    r!   reportsr)   config
py_version
msgs_store
msg_status_by_id_managed_msgsr4   
file_statecurrent_namecurrent_file_ignore_file_ignore_pathsregister_checker)rF   r   r   r   r   	opt_groups         rG   r   zPyLinter.__init__  s    	"4h7777%dD111 	G 	.h''''lnn---CEC
 #D)) 	 	ATV) !]]
 !(*>t*D*D D& 	B 	BI5>q\D$Yq\22;H L
 <
 +-T %..t444%%dD111 -/JK//
 z#89
 11GHH9;  $B4PPP(,(,!13d#####rI   c                H    t          j        dt          d           | j        S NzQThe option_groups attribute has been deprecated and will be removed in pylint 3.0   
stacklevelwarningswarnDeprecationWarningr   rF   s    rG   r   zPyLinter.option_groupsX  s1     	_	
 	
 	
 	

 ""rI   valuec                L    t          j        dt          d           || _        d S r   r   )rF   r   s     rG   r   zPyLinter.option_groupsb  s4    _	
 	
 	
 	

 $rI   c                V    t          j        |            t          j        |            d S rD   )r   
initializer   r   s    rG   load_default_pluginszPyLinter.load_default_pluginsk  s*    D!!!T"""""rI   modnames	list[str]c                    |D ]l}|| j         v r	 t          j                            |          }|                    |            || j         |<   L# t
          $ r}|| j         |<   Y d}~ed}~ww xY wdS )zCheck a list of pylint plugins modules, load and register them.

        If a module cannot be loaded, never try to load it again and instead
        store the error message for later use in ``load_plugin_configuration``
        below.
        N)r   r\   r]   r_   registerModuleNotFoundError)rF   r   r>   re   mnf_es        rG   load_plugin_moduleszPyLinter.load_plugin_moduleso  s       	7 	7G$// 7 )??HH%%%17%g..& 7 7 716%g......7	7 	7s   >A
A-
A((A-c                >   | j                                         D ]Z\  }}t          |t                    r|                     d||fd           5t          |d          r|                    |            [d | j                                         D             | _         dS )a  Call the configuration hook for plugins.

        This walks through the list of plugins, grabs the "load_configuration"
        hook, if exposed, and calls it to allow plugins to configure specific
        settings.

        The result of attempting to load the plugin of the given name
        is stored in the dynamic plugins dictionary in ``load_plugin_modules`` above.

        ..note::
            This function previously always tried to load modules again, which
            led to some confusion and silent failure conditions as described
            in GitHub issue #7264. Making it use the stored result is more efficient, and
            means that we avoid the ``init-hook`` problems from before.
        r   r   )argslineload_configurationc                B    i | ]\  }}|t          |t                     S rE   )rQ   r   ).0r>   vals      rG   
<dictcomp>z6PyLinter.load_plugin_configuration.<locals>.<dictcomp>  s<     !
 !
 !
 C)<===!
 !
 !
rI   N)r   itemsrQ   r   add_messagehasattrr   )rF   r>   module_or_errors      rG   load_plugin_configurationz"PyLinter.load_plugin_configuration  s      )-(=(C(C(E(E 	9 	9$G_/+>?? 9  &g-Ga !     *>?? 9224888
!
 !
 $ 5 ; ; = =!
 !
 !
rI   reporter_namesc           	        | j         sdS g }g }t          j                    5 }|                    d          D ]}|                    dd          ^}}|                     |          }|                    |           |rG|                    t          |d         dd                    }||_        |                    |           |	                                j
        }	ddd           n# 1 swxY w Y   t          |          dk    s|r*|                     t          j        ||	                     dS |                     |d                    dS )	z7Load the reporters if they are available on _reporters.N,:r   r   wrN   rO   )r   
contextlib	ExitStackr`   _load_reporter_by_nameappendenter_contextopenoutpop_allcloselenr   r   MultiReporter)
rF   r   sub_reportersoutput_filesstackreporter_namereporter_outputr   output_fileclose_output_filess
             rG   _load_reporterszPyLinter._load_reporters  s    	F!## 	7u!/!5!5c!:!: 
5 
52?2E2Ec12M2M/66}EE$$X..." 5"'"5"5_Q/wGGG# #K $/HL ''444 "'!6	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7  }! 	0\ 	0'!&      mA./////s   B=C**C.1C.r   reporters.BaseReporterc                   |                                 }|| j        v r | j        |                     S 	 t          |          }n4# t          t          t
          f$ r}t          j        |          |d }~ww xY w |            S rD   )lowerr   rh   ImportErrorAttributeErrorAssertionErrorr   InvalidReporterError)rF   r   namerW   es        rG   r   zPyLinter._load_reporter_by_name  s    ""$$4?" 	+(4?4(***	?4]CCNN^^< 	? 	? 	?1$77Q>	? ~s   A A5A00A50reporters.BaseReporter | reporters.MultiReporterc                "    || _         | |_        dS )z6Set the reporter used to display messages and reports.N)r   linter)rF   r   s     rG   r   zPyLinter.set_reporter  s     !rI   rW   type[reporters.BaseReporter]c                $    || j         |j        <   dS )z7Registers a reporter class on the _reporters attribute.N)r   r   )rF   rW   s     rG   register_reporterzPyLinter.register_reporter  s    /=+,,,rI   list[BaseChecker]c                    t          | j        d           }	 |                    |                    |                      |                    |            n# t
          $ r Y nw xY w|S )Nc                $    t          | dd          S )Nr   r   )ra   )xs    rG   <lambda>z'PyLinter.report_order.<locals>.<lambda>  s    ga6L6L rI   )key)sorted_reportspopindexr   
ValueError)rF   r   s     rG   report_orderzPyLinter.report_order  s    ,L,LMMM	! KKd++,,, NN4      	 	 	D	 s   (A 
A$#A$checkercheckers.BaseCheckerc                   | j         |j                                     |           |j        D ]\  }}}|                     ||||           t          |d          rE| j                            |           |j        D ]#}|j	        s| 
                    |j                   $t          |dd          s| 
                    |j                   dS dS )z'This method auto registers the checker.msgsenabledTN)r   r   r   r   register_reportr   r   register_messages_from_checkermessagesdefault_enableddisablemsgidra   )rF   r  r_idr_titler_cbmessages         rG   r   zPyLinter.register_checker  s    w|$++G444#*? 	? 	?D'4  wg>>>>7F## 	0O::7CCC"+ 0 0. 0LL///w	400 	'LL&&&&&	' 	'rI   c                   | j         j        }|sdS t                      }t                      }|D ]6}|t          v r|                    |           !|                    |           7| j                                        D ]}|D ]}|j        D ]|}|j        |v s	|j	        |v r:| 
                    |j                   | j                            |j	                   N|j        d         |v r| j                            |j	                   }dS )zEnable 'fail on' msgs.

        Convert values in config.fail_on (which might be msg category, msg id,
        or symbol) to specific msgs, then enable and flag them for later.
        Nr   )r   fail_onsetr   addr   valuesr  r  symbolenabler   r   )rF   fail_on_valsfail_on_catsfail_on_msgsr   all_checkersr  msgs           rG   enable_fail_on_messagesz PyLinter.enable_fail_on_messages  sR    {* 	Fuuuu 	& 	&Ci &  %%%%  %%%% !N1133 		@ 		@L' @ @"+ @ @CyL0 @CJ,4N @CI...,33CJ????15 @,33CJ???@@		@ 		@rI   boolc                r     t           fd j        j                                        D                       S )Nc              3  *   K   | ]}|j         v V  d S rD   )r   )r   r  rF   s     rG   	<genexpr>z.PyLinter.any_fail_on_issues.<locals>.<genexpr>  s+      OO1,,OOOOOOrI   )anyr   by_msgkeysr   s   `rG   any_fail_on_issueszPyLinter.any_fail_on_issues  s7    OOOOdj6G6L6L6N6NOOOOOOrI   c                z    | j                                         D ] }|D ]\  }}}|                     |           !dS )zDisable all reporters.N)r	  r!  disable_report)rF   r   	report_id_s       rG   disable_reporterszPyLinter.disable_reporters  sZ    -..00 	/ 	/J#- / /	1a##I..../	/ 	/rI   c                    | j         sdS |                                  |                     d           |                     dd           |                     dd           |                     dd           dS )zwParse the current state of the error mode.

        Error mode: enable only errors; no reports, no persistent.
        Nmiscellaneousr   F
persistentscore)r   disable_noerror_messagesr  
set_optionr   s    rG   _parse_error_modezPyLinter._parse_error_mode  sz    
  	F%%'''_%%%	5)))e,,,'''''rI   c                b    t          d | j                                        D                       S )z1Return all available checkers as an ordered list.c              3  $   K   | ]}|D ]}|V  d S rD   rE   )r   r   cs      rG   r-  z(PyLinter.get_checkers.<locals>.<genexpr>-  s/      TTI)TTQaTTTTTTTrI   )r  r   r!  r   s    rG   get_checkerszPyLinter.get_checkers+  s-    TT)>)>)@)@TTTTTTrI   c                X    t          d |                                 D                       S )z7Get all the checker names that this linter knows about.c                <    h | ]}|j         t          k    |j         S rE   )r   r   )r   r  s     rG   	<setcomp>z-PyLinter.get_checker_names.<locals>.<setcomp>2  s8       <#44  rI   )r  rA  r   s    rG   get_checker_nameszPyLinter.get_checker_names/  s<     #0022  
 
 	
rI   c                      j         j        s                                   g}                                 dd         D ]L} fd|j        D             }|s t           fd|j        D                       r|                    |           M|S )z:Return checkers needed for activated messages and reports.r   Nc                >    h | ]}                     |          |S rE   )is_message_enabled)r   r(  rF   s     rG   rD  z,PyLinter.prepare_checkers.<locals>.<setcomp>@  s,    TTTt7N7Ns7S7STTTTrI   c              3  N   K   | ]}                     |d                    V   dS )r   N)report_is_enabled)r   rrF   s     rG   r-  z,PyLinter.prepare_checkers.<locals>.<genexpr>A  s5      UUt55ad;;UUUUUUrI   )r   r   r6  rA  r  r.  r   )rF   needed_checkersr  r  s   `   rG   prepare_checkerszPyLinter.prepare_checkers9  s    {" 	%""$$$.2V((**122. 	0 	0GTTTTw|TTTH 03UUUUW_UUUUU 0&&w///rI   Fr>   pathis_argumentc                4    |rdS |                     d          S )a  Returns whether a module should be checked.

        This implementation returns True for all python source file, indicating
        that all files should be linted.

        Subclasses may override this method to indicate that modules satisfying
        certain conditions should not be linted.

        :param str modname: The name of the module to be checked.
        :param str path: The full path to the source code of the module.
        :param bool is_argument: Whether the file is an argument to pylint or not.
                                 Files which respect this property are always
                                 checked, since the user requested it explicitly.
        :returns: True if the module should be checked.
        T.py)endswith)r>   rN  rO  s      rG   should_analyze_filezPyLinter.should_analyze_fileF  s#    "  	4}}U###rI   c                    | j         j        | _        | j        j        D ]0}|                    | j         j                  sd| j        |j        <   1dS )zbInitialize linter for linting.

        This method is called before any linting is done.
        FN)	r   ignore_pathsr   r   r  may_be_emittedr   _msgs_stater  )rF   r(  s     rG   r   zPyLinter.initialize]  s\    
 "[5 ?+ 	4 	4C%%dk&<== 4.3 +	4 	4rI   files_or_modulesSequence[str]Iterator[str]c              #  @  K   |D ]}t           j                            |          rt           j                            t           j                            |d                    sg }t          j        |          D ]\  }}t          fd|D                       r"t          | j        j	        | j        j
        | j        j                  r|                               hd|v r|                               V  fd|D             E d{V  |V  dS )zDiscover python modules and packages in sub-directory.

        Returns iterator of paths to discovered modules and packages.
        z__init__.pyc              3  B   K   | ]}                     |          V  d S rD   )
startswith)r   sroots     rG   r-  z+PyLinter._discover_files.<locals>.<genexpr>t  s/      EE!4??1--EEEEEErI   c              3     K   | ]9}|                     d           t          j                            |          V  :dS )rQ  N)rR  osrN  join)r   filer_  s     rG   r-  z+PyLinter._discover_files.<locals>.<genexpr>  sY       $ $ $#}}U33$GLLt44$ $ $ $ $ $rI   N)ra  rN  isdirisfilerb  walkr.  r   r   ignoreignore_patternsrU  r   )rF   rX  	somethingskip_subtreesr5  filesr_  s         @rG   _discover_fileszPyLinter._discover_filesi  s     
 * 	  	 Iw}}Y''  Y661 1   ,.&(gi&8&8  ND!UEEEE}EEEEE ! '*30	  ! &,,T222 $- %,,T222"



$ $ $ $(-$ $ $        %0  ;	  	 rI   Sequence[str] | strc                (   |                                   t          |t          t          f          st	          j        dt          d           |f}| j        j        r"t          | 	                    |                    }| j        j
        r't          |          dk    rt          j        d          | j        j
        sa| j        j        dk    rQt          j        dd         }t#          | | j        j        |                     |          |           |t          _        dS t'          |          5  | j        j
        r*|                     |d                   }t+                      }n|                     |          }d}ddd           n# 1 swxY w Y   t'          |          5  |                                 5 }|                     ||          }|                     ||           ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )zMain checking entry: check a list of files or modules from their name.

        files_or_modules is either a string or list of strings presenting modules to check.
        zNIn pylint 3.0, the checkers check function will only accept sequence of stringr   r   r   z*Missing filename required for --from-stdinNr   )r   rQ   r   tupler   r   r   r   	recursiverl  
from_stdinr   r   InvalidArgsErrorjobsrR   rN  r   _iterate_file_descrsr$   _get_file_descr_from_stdinrV   _astroid_module_checker	_get_asts_lint_files)rF   rX  original_sys_path	fileitemsr?   check_astroid_moduleast_per_fileitems          rG   checkzPyLinter.check  s    	 *T5M:: 	3M`"   
 !12;  	M$T%9%9:J%K%KLL;! 	#$$)  1@  
 {% 		$+*:Q*> 		 # ))*:;; 	   )CHF -.. 	 	{%  ;;<LQ<OPP	#.== 556FGG		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 -.. 	I 	I--// I3G#'>>)T#B#B    !13GHHHI I I I I I I I I I I I I I I	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	IsI   -AFFF!H6-G/#H/G3	3H6G3	7HHHrz  Iterator[FileItem]r?   #dict[FileItem, nodes.Module | None]c                ~   i }|D ]}|                      |j        |j                   	 |                     |j        |j        |          ||<   H# t          j        $ r^}t          ||j        | j                  }t          |j        |          }| 	                    d|j        |ft                     Y d}~d}~ww xY w|S )z$Get the AST for all given FileItems.rm   r   
confidenceN)set_current_moduler   r<   get_astr\   AstroidBuildingErrorr&   r   r%   r   r   )rF   rz  r?   r|  fileitemextemplate_pathr(  s           rG   rw  zPyLinter._get_asts  s    AC! 	 	H##HM83DEEE-1\\%x}d. . ** / 	 	 	 4)4+?! ! .h.?OO  #"+S1# !        	  s   $AB:AB55B:r   r<   c                    t          j        dt          d           |                     t	          |||                     d S )NzkIn pylint 3.0, the checkers check_single_file function will be removed. Use check_single_file_item instead.r   r   )r   r   r   check_single_file_itemr-   )rF   r   r<   r>   s       rG   check_single_filezPyLinter.check_single_file  sN    2		
 	
 	
 	
 	##HT8W$E$EFFFFFrI   rc  r-   c                    |                                  5 }|                     | j        ||           ddd           dS # 1 swxY w Y   dS )zCheck single file item.

        The arguments are the same that are documented in _check_files

        initialize() should be called before calling this method
        N)rv  _check_filer  )rF   rc  r{  s      rG   r  zPyLinter.check_single_file_item  s     ))++ 	G/CT\+?FFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	Gs   ?AAast_mappingr{  %Callable[[nodes.Module], bool | None]c                   |                                 D ]\  }}|	 |                     |||           !# t          $ r}t          ||j        | j                  }t          |j        |          }t          |t          j	                  r%| 
                    d|j        |ft                     n| 
                    d|t                     Y d}~d}~ww xY wdS )z%Lint all AST modules from a mapping..Nrm   r  rj   )r   
_lint_file	Exceptionr&   r<   r   r%   rQ   r\   AstroidErrorr   r   )rF   r  r{  r  re   r  r  r(  s           rG   rx  zPyLinter._lint_files  s    !, 1 1 3 3 	I 	IHf I&2FGGGG 
I 
I 
I 4)4+?! ! .h.?OOb'"677 I$$'x/@#.FSW %     $$W34$HHH
I	I 	Is   6
C BCCre   rB   c                   |                      |j        |j                   d| _        t	          |j        | j        |          | _        |j        | _	        	  ||           n# t          $ r}t          j        |d}~ww xY w| j                            | j                  }|D ]\  }}}|                     ||d|           dS )a  Lint a file using the passed utility function check_astroid_module).

        :param FileItem file: data about the file
        :param nodes.Module module: the ast module to lint
        :param Callable check_astroid_module: callable checking an AST taking the following arguments
        - ast: AST of the module
        :raises AstroidError: for any failures stemming from astroid
        FNr  r   r<   r   r4   modpathr   r   rc  r   r  r\   r  "iter_spurious_suppression_messagesr   )	rF   rc  re   r{  r   spurious_messagesr  r   r   s	            rG   r  zPyLinter._lint_file  s     		4=999!#DL$/6JJ #K	.  (((( 	. 	. 	.&A-	. !ONNO
 
 "3 	6 	6E4UD$5555	6 	6s   A! !
A=+A88A=r  r;   c                   |                      |j        |j                    ||j        |j                  }|dS d| _        t	          |j        | j        |          | _        |j        | _	        	  ||           n# t          $ r}t          j        |d}~ww xY w| j                            | j                  }|D ]\  }}}	|                     ||d|	           dS )a  Check a file using the passed utility functions (get_ast and
        check_astroid_module).

        :param callable get_ast: callable returning AST from defined file taking the following arguments
        - filepath: path to the file to check
        - name: Python module name
        :param callable check_astroid_module: callable checking an AST taking the following arguments
        - ast: AST of the module
        :param FileItem file: data about the file
        :raises AstroidError: for any failures stemming from astroid
        NFr  )
rF   r  r{  rc  ast_noder   r  r  r   r   s
             rG   r  zPyLinter._check_file)  s   " 		4=99974=$)44 	F!#DL$/8LL %M	.  **** 	. 	. 	.&A-	. !ONNO
 
 "3 	6 	6E4UD$5555	6 	6s   /A; ;
BBBc              #    K   t          || j        j        | j        j        | j        j                  rdS 	 d                    t          j                            |                    }nR# t          $ rE t          j                            t          j                            |                    d         }Y nw xY wt          |||          V  dS )zReturn file description (tuple of module name, file path, base name) from
        given file path.

        This method is used for creating suitable file description for _check_files when the
        source is standard input.
        NrZ   r   )r   r   rg  rh  rU  rb  r\   r]   modpath_from_filer   ra  rN  splitextbasenamer-   )rF   r<   r>   s      rG   ru  z#PyLinter._get_file_descr_from_stdinQ  s       KK'K$	
 
 	 F	F hhw/AA(KKLLGG 	F 	F 	Fg&&rw'7'7'A'ABB1EGGG	F w(3333333s   2A) )AB87B8c              #     K   |                      |                                          D ]K}|d         |d         |d         }}}|                     |||          rt          |||d                   V  LdS )zReturn generator yielding file descriptions (tuples of module name, file
        path, base name).

        The returned generator yield one item for each Python module that should be linted.
        r   rN  isarg)rO  r  N)_expand_filesr!  rS  r-   )rF   rX  descrr   r<   is_args         rG   rt  zPyLinter._iterate_file_descrsj  s       ''(899@@BB 	B 	BE%*6]E&M5>F(D''hF'KK BtXuZ/@AAAAA	B 	BrI   modules dict[str, ModuleDescriptionDict]c                   t          || j        j        | j        j        | j                  \  }}|D ]}|d         x}}|d         }|                     |           |dk    rGt          |d                                       t          j	                    t          j
        z   d          }|                     ||           |S )z@Get modules and errors from a list of modules and handle errors.modr  rj   r  r   r   )r   r   rg  rh  r   r  r=   replacera  getcwdsepr   )rF   r  resulterrorserrorr  r>   r  s           rG   r  zPyLinter._expand_filesw  s    'KK'	
 
  	0 	0E %e,Gg,C##G,,,g~ MeDk**2229;;3GLLSw////rI   c                \   |s|dS | j                             |pd|           |t          j        dt          d           || _        |p|| _        | j                            |pd           |r:| 	                    t          |          | j                  }|r|p| j        | _        dS dS dS )zZSet the name of the currently analyzed module and
        init statistics for it.
        Nr   zIn pylint 3.0 modname should be a string so that it can be used to correctly set the current_name attribute of the linter instance. If unknown it should be initialized as an empty string.r   r   )r   on_set_current_moduler   r   r   r   r   r   init_single_module_get_namespace_for_filer	   _directory_namespaces_base_configr   )rF   r>   r<   	namespaces       rG   r  zPyLinter.set_current_module  s      	8 	F++GMr8DDD 
	MN #    $$/
%%gm444  	=44X : I  ='<4+<	= 	== =rI   r	   
namespacesr,   argparse.Namespace | Nonec                    |D ]F}t          ||          r4|                     |||         d                   }|||         d         c S Gd S )Nr   r   )r#   r  )rF   r<   r  	directoryr  s        rG   r  z PyLinter._get_namespace_for_file  so     $ 	4 	4Ix33 4 88j3A6 	  4%i03333trI   /Iterator[Callable[[nodes.Module], bool | None]]c              #    K   t          |           }|                                 }d |D             }|D ]}t          j                    5  t          j        dt
                     t          j        |t          j                  r7||vr3|| ur/|	                    |           t          j
        dt
                     ddd           n# 1 swxY w Y   d |D             }|D ]}t          j                    5  t          j        dt
                     t          j        |t          j                  r3||vr/|	                    |           t          j
        dt
                     ddd           n# 1 swxY w Y   |D ]+}|                                 |                    |           ,t          j        | j        |||          V  |j        | j        _        t)          |          D ]}|                                 dS )	z}Context manager for checking ASTs.

        The value in the context is callable accepting AST as its only argument.
        c                F    g | ]}t          |t          j                  |S rE   )rQ   r   BaseTokenCheckerr   r@  s     rG   
<listcomp>z4PyLinter._astroid_module_checker.<locals>.<listcomp>  s:     
 
 
Jq(2K$L$L

 
 
rI   rg  )categoryzCheckers should subclass BaseTokenChecker instead of using the __implements__ mechanism. Use of __implements__ will no longer be supported in pylint 3.0Nc                F    g | ]}t          |t          j                  |S rE   )rQ   r   BaseRawFileCheckerr  s     rG   r  z4PyLinter._astroid_module_checker.<locals>.<listcomp>  s:     
 
 
Jq(2M$N$N

 
 
rI   zCheckers should subclass BaseRawFileChecker instead of using the __implements__ mechanism. Use of __implements__ will no longer be supported in pylint 3.0)walkertokencheckersrawcheckers)r3   rM  r   catch_warningsfilterwarningsr   r   
implementsITokenCheckerr   r   IRawCheckerr   add_checker	functoolspartialr{  nbstatementsr   	statementreversedr   )rF   r  r   r  r@  r  r  s          rG   rv  z PyLinter._astroid_module_checker  s      4))++	
 
 
 
 
  	 	A(**  ';MNNNN)!Z-EFF. 
 "((+++MD +	                
 
 
 
 
  	 	A(**  ';MNNNN)!Z-CDD
,
  &&q)))MD +	                 ! 	( 	(GLLNNNw''''%'#	
 
 
 	
 	
 	
  &2
	** 	 	GMMOOOO	 	s&   	A2CC	C	6A.E00E4	7E4	nodes.Module | Nonec           
     f   	 |t                               ||d          S t          j                            t                                         |||          S # t          j        $ r`}t          |j        dd          }|d}| 	                    d|t          |j        dd          d|j         d	t          
           Y d}~nmd}~wt          j        $ r!}| 	                    d|           Y d}~n?d}~wt          $ r/}t          j                     t          j        d|          |d}~ww xY wdS )a  Return an ast(roid) representation of a module or a string.

        :param filepath: path to checked file.
        :param str modname: The name of the module to be checked.
        :param str data: optional contents of the checked file.
        :returns: the AST
        :rtype: astroid.nodes.Module
        :raises AstroidBuildingError: Whenever we encounter an unexpected exception
        NT)sourcelinenor   r|   offsetzParsing failed: '')r   
col_offsetr   r  ro   r  zMBuilding error when trying to create ast representation of module '{modname}')r>   )MANAGERast_from_filer\   builderAstroidBuilderstring_buildAstroidSyntaxErrorra   r  r   r   r  r  	traceback	print_exc)rF   r<   r>   r?   r  r   s         rG   r  zPyLinter.get_ast  s   	 M,,Xwt,LLL?11'::GGgx   ) 
	 
	 
	28Xt44D "28Xt<<4444          + 	5 	5 	5]44444444 	 	 	!!! ._   	 ts5   A 8A D.)ACD.C22D.?*D))D.r  r  r3   r  !list[checkers.BaseRawFileChecker]r  list[checkers.BaseTokenChecker]bool | Nonec                    |j         }|                     ||||          }| j        sJ |j         |z
  | j        j        | j                 d<   |S )zlCheck a module from its astroid representation.

        For return value see _check_astroid_module
        r  )r  _check_astroid_moduler   r   	by_module)rF   r  r  r  r  before_check_statementsretvals          rG   r{  zPyLinter.check_astroid_module  sh     #)"5++fk=
 

      "99 	
T./< rI   nodec                   	 t          j        |          }nQ# t          j        $ r?}|                     d|j        d         d         |j        d                    Y d}~dS d}~ww xY w|j        s|                     d|j                   nR|                     |           | j	        rdS |D ]}|
                    |           |D ]}|                    |           |                    |           d	S )
a  Check given AST node with given walker and checkers.

        :param astroid.nodes.Module node: AST node of the module to check
        :param pylint.utils.ast_walker.ASTWalker walker: AST walker
        :param list rawcheckers: List of token checkers to use
        :param list tokencheckers: List of raw checkers to use

        :returns: True if the module was checked, False if ignored,
            None if the module contents could not be parsed
        r|   r   r   )r   r   Nrr   r  FT)r6   tokenize_moduletokenize
TokenErrorr   r   pure_pythonr   process_tokensr   process_modulerf  )	rF   r  r  r  r  tokensr  raw_checkertoken_checkers	            rG   r  zPyLinter._check_astroid_module8  s(   "	*400FF" 	 	 	^"'!*Q-bgajQQQ44444	  	51	BBBB '''  u* 1 1**40000!. 5 5,,V4444Dts    A%4A  A%c                r   t                      | _        | j        j        t          _        | j        j        t          _        t          j        	                    | j        j
                   | j        j        r)t          j        	                    | j        j                   | j                                         dS )zInitialize counters.N)r5   r   r   unsafe_load_any_extensionr  always_load_extensionslimit_inference_resultsmax_inferable_valuesextension_package_whitelistupdateextension_pkg_allow_listextension_pkg_whitelistreset_message_countr   s    rG   r   zPyLinter.open`  s     ]]
)-)N&'+{'J$+224;3WXXX;. 	/663   	
&&(((((rI   
int | Nonec                   | j                             t          j                               | j        j        s| j        j        t          | j        j                  }| j                             | j	        |           | j
        j        r|                     | j	        |          }nt          j                    }| j
        j        r| j                             |           |                                 }| j
        j        rt!          | j	        | j        j                   n.| j                             | j	        t#                                 d}|S )zClose the whole package /module, it's time to make reports !

        if persistent run, pickle results for later comparison
        N)r   display_messagesreport_nodesSectionr   _is_base_filestate	base_namer   on_closer   r   r   make_reportsdisplay_reports_report_evaluationr9  r   r5   )rF   previous_statssectscore_values       rG   generate_reportszPyLinter.generate_reportsl  s$    	&&|';'='=>>> 2	)	
 *$/*CDDNM""4:~>>>{" .((^DD#+--{" 4--d3331133K{% DTZ)BCCCM""4:{}}===KrI   c                d   d}| j         j        J t          | j         j                  }| j        j        dk    r|S | j        j        }	 | j        j        | j        j        | j        j	        | j        j
        | j        j        | j        j        | j        j        d}t          |i |          }|| j        _        d|dd}|r|j        }||d|dd||z
  d	d
z  }n# t          $ r}d| }Y d}~nd}~ww xY w| j        j        r.t#          j        |          }| j                            |           |S )z"Make the global evaluation report.Nr   )rj   r  warningrefactor
conventionr  infozYour code has been rated at z.2fz/10z (previous run: z/10, z+.2f)z$An exception occurred while rating: )r   r  r   r   r  r   
evaluationrj   r  r  r  r  r  evalglobal_noter  r:  r   EvaluationSectionr   r  )	rF   noter  r  
stats_dictr(  pnoter  r	  s	            rG   r  zPyLinter._report_evaluation  s    (444%do&?@@:1$ 	K [+
	S)):- J/"j3!Z1
 J 
B
33D &*DJ">>>>>C S&2 SReRRRdUlRRRRRC  	> 	> 	>===CCCCCC	> ; 	01#66DM))$///s   	A!C 
C3$C..C3message_definitionr(   r   nodes.NodeNG | Noner   
Any | Noner  interfaces.Confidence | Noner  
end_linenoend_col_offsetc	                   |                     ||           |rd|j        r9|s|j        j        }|s|j        j        }|s|j        j        }|s|j        j        }n$|s|j        }|s|j        }|s|j        }|s|j        }|                     |j        ||          s=| j	        
                    |                     |j        ||          |j        |           dS t          |j        d                  }	| xj        t          |j        d                  z  c_        | j                            |	d           | j                            | j        |	d           	 | j        j        |j        xx         dz  cc<   n$# t*          $ r d| j        j        |j        <   Y nw xY w|j        }
||
|z  }
|| j        d}}| j        }n0t1          j        |          \  }}|                                j        }|"|                    | j        j        dd          }nd}| j                            tA          |j        |j        tC          |pd||pd||pd|pd||          |
|                     dS )zpAfter various checks have passed a single Message is
        passed to the reporter and added to stats.
        Nr   r   r   configuration)"check_message_definitionpositionr  r  r  r  
fromlinenorH  r  r   handle_ignored_message_get_message_state_scoper   r   r   r   increase_single_message_count$increase_single_module_message_countr   r/  r"  KeyErrorr(  r   r6   get_module_and_frameidr_  rc  r  r   path_strip_prefixhandle_messager'   r0   )rF   r  r   r  r   r  r  r  r  msg_catr(  re   objabspathrN  s                  rG   _add_one_messagezPyLinter._add_one_message  s    	33D$???  	9} 9 0=/D! :!%!9J! :!%!9J% B%)]%AN +?D! 1!%J! 1!%J% 9%)%8N &&'9'?zRR 	O22--&,dJ  #(   F .4Q78+,>,DQ,GHH
00!<<<
77	
 	
 	

	=J07888A=8888 	= 	= 	=;<DJ07888	= !$ 	4KC 	'+RCF'GG6t<<KFCiikk&G 	#??4=#BBJJDD"D$$"(")$MrLbIAO!"	 	  	
 	
 	
 	
 	
s   E1 1FFr  c	                    |t           j        }| j                            |          }	|	D ]}
|                     |
|||||||           dS )a,  Adds a message given by ID or name.

        If provided, the message string is expanded using args.

        AST checkers must provide the node argument (but may optionally
        provide line if the line number is different), raw and token checkers
        must provide the line argument.
        N)r   	UNDEFINEDr   get_message_definitionsr/  )rF   r  r   r  r   r  r  r  r  message_definitionsr  s              rG   r   zPyLinter.add_message  sy    &  	.#-J"oEEeLL"5 
	 
	!!"	 	 	 	
	 
	rI   intc                    | j                             |          }|D ]S}|                    ||           | j                            |                     |j        ||          |j        |           TdS )ah  Prepares a message to be added to the ignored message storage.

        Some checks return early in special cases and never reach add_message(),
        even though they would normally issue a message.
        This creates false positives for useless-suppression.
        This function avoids this by adding those message to the ignored msgs attribute
        N)r   r2  r!  r   r$  r%  r  )rF   r  r   r  r  r3  r  s          rG   add_ignored_messagezPyLinter.add_ignored_message6  s     #oEEeLL"5 	 	77dCCCO22--&,dJ  #(   	 	rI   c                   | j                                         D ]G\  }}|\  }}| j                            |           |D ] }|                     ||dt
                     !Ht          j        t                    | _         d S )Nr   )r   r   r  )	_stashed_messagesr   r   r  r   r   r   r   r   )rF   r0  r!  r>   r"  r   s         rG   _emit_stashed_messageszPyLinter._emit_stashed_messagesO  s     288:: 		 		LD&"OGVK**7333    #	 !     "-!8!>!>rI   )rE   NrE   N)
r   r2   r   r   r   r   r   r@   rA   r   )rA   r   )r   r   rA   r   )rA   r   )r   r   rA   r   )r   r=   rA   r   )r   r=   rA   r   )r   r   rA   r   )rW   r   rA   r   )rA   r  )r  r  rA   r   )rA   r*  )rA   r   )F)r>   r=   rN  r=   rO  r*  rA   r*  )rX  rY  rA   rZ  )rX  rm  rA   r   )rz  r~  r?   r@   rA   r  )r   r=   r<   r=   r>   r=   rA   r   )rc  r-   rA   r   )r  r  r{  r  rA   r   )rc  r-   re   rB   r{  r  rA   r   )r  r;   r{  r  rc  r-   rA   r   )r<   r=   rA   r~  )rX  rY  rA   r~  )r  rY  rA   r  rD   )r>   r@   r<   r@   rA   r   )r<   r	   r  r,   rA   r  )rA   r  )r<   r=   r>   r=   r?   r@   rA   r  )
r  rB   r  r3   r  r  r  r  rA   r  )
r  rB   r  r3   r  r  r  r  rA   r  )rA   r  )r  r(   r   r  r  r  r   r  r  r  r  r  r  r  r  r  rA   r   )NNNNNNN)r  r=   r   r  r  r  r   r  r  r  r  r  r  r  r  r  rA   r   )
r  r=   r   r4  r  r  r  r  rA   r   )>rJ   rK   rL   __doc__r   r   r   r  r   __annotations__r   r   propertyr   setterr   r   r   r   r   r   r  r  r   r)  r1  r6  r=  rA  rE  rM  staticmethodrS  r   rl  r}  rw  r  r  rx  r  r  ru  rt  r  r  r  r   contextmanagerrv  r  r{  r  r   r  r  r/  r   r   r1  r6  r9  rE   rI   rG   r   r      s           DD?O???? DG  LP57#G$ G$ G$ G$ G$R # # # X# $ $ $ $# # # #7 7 7 7"
 
 
 
@0 0 0 0@
  
  
  
    > > > >
 
 
 
' ' ' '@ @ @ @>P P P P/ / / /( ( ( ( U U U U
 
 
 

 
 
 
 $ $ $ $ \$,
4 
4 
4 
4"  "  "  " H5I 5I 5I 5In       4G G G GG G G GI I I I.6 6 6 6B&6 &6 &6 &6P4 4 4 42B B B B   $ ;?= = = = =@
 
 
 
 = = = =@ ?C( ( ( ( (T   4& & & &P
) 
) 
) 
)   @% % % %N_
 _
 _
 _
H  $(37!%!%%)         L %)3=3G    2? ? ? ? ? ?rI   r   )rA   r=   )rW   r=   rA   rX   )d
__future__r   argparser   r   r  ra  rR   r  r  r   r   collections.abcr   r   r   ior   pathlibr	   rer
   typesr   typingr   r\   r   r   r   r   r   r   pylint.checkers.base_checkerr   pylint.config.arguments_managerr   pylint.constantsr   r   r   r   pylint.interfacesr   pylint.lint.base_optionsr   pylint.lint.cachingr   r   pylint.lint.expand_modulesr   r   !pylint.lint.message_state_handlerr   pylint.lint.parallelr   pylint.lint.report_functionsr    r!   r"   pylint.lint.utilsr#   r$   r%   r&   pylint.messager'   r(   r)   pylint.reporters.base_reporterr*   pylint.reporters.textr+   pylint.reporters.ureportsr   pylint.typingr,   r-   r.   r/   r0   r1   r2   pylint.utilsr3   r4   r5   r6   version_infor9   typing_extensionsr  r;   rV   rh   LINEr   r;  r   r   rE   rI   rG   <module>r\     sD  
 # " " " " " "              				 



       # # # # # # 8 8 8 8 8 8 8 8 8 8                                      > > > > > > > > > > > > 4 4 4 4 4 4 = = = = = =            # " " " " " 9 9 9 9 9 9 : : : : : : : : G G G G G G G G B B B B B B / / / / / /         
            N M M M M M M M M M 7 7 7 7 7 7 . . . . . . ; ; ; ; ; ;                  B A A A A A A A A A A Av +****** /    X         C+	8	,#$C+ 	1 
,#$C+  &	<	,#$!C+. 3T	,#$	/C+: :	"	,#$;C+H -	"	,#$IC+V #O	,#$	WC+b :	,#$	cC+n &	 
,#$oC+@ #	0	,#$AC+N 5	> >>!&	
 	

OC+d :	,#$	eC+p %$<	,#$	qC+| UB!&78	
 	
	}C+N +	 "&78	
 	
	OC+b E:	,#$	cC+n Y#i	,#$	oC+z 'A	,#$	{C+ C+ C C C CNk? k? k? k? k?!	k? k? k? k? k?rI   