
    yIfؾ                       U d Z ddlm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
 ddlmZ ddlmZmZmZmZmZ ddlZddlmZ dd	lmZ dd
lmZmZ ddlmZmZ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' ddl(m)Z) ddl*m+Z+m,Z,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 erddl4m5Z5 ee6eeee6ef                  ee6         f         f         Z7ddhdhdhdhdhh ddhh dh dh dd 
Z8dqd.Z9drd3Z:dsd7Z;dtdud:Z<dvd>Z=dwdCZ>i dDdEdFdGdHdIgifdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgZ?dhe@di<   djZAdkZBdjZC G dl dmee          ZDdxdpZEdS )yz!Imports checkers for Python code.    )annotationsN)defaultdict)	ItemsViewSequence)cached_property)TYPE_CHECKINGAnyDictListUnion)nodes)
ImportNode)BaseCheckerDeprecatedMixin)get_import_namein_type_checking_blockis_from_fallback_blockis_module_ignoredis_sys_guardnode_ignores_exception)MAX_NUMBER_OF_IMPORT_SHOWN)EmptyReportError)
DotBackend
get_cycles)HIGH)	ParagraphSectionVerbatimText)MessageDefinitionTuple)IsortDriver)LinterStats)PyLinterztkinter.tixfpectloptparsezxml.etree.cElementTreeimp	formatter>   smtpdasynchatasyncoremacpath>   binhexparsersymbollib2to3>   	typing.io	typing.re	distutils>   uucginisaifcspwdcgitbchunkcryptpipessunauimghdrmsilibsndhdrxdrlibaudioopmailcapnntplib	sre_parse	telnetlibossaudiodevsre_compilesre_constants)
)r   r   r   )      r   )rH   rH   r   )rH      r   )rH      r   )rH      r   )rH      r   )rH   	   r   )rH   
   r   )rH      r   noder   contextnodes.LocalsDictNodeNGnamestrbase
str | Nonelevel
int | Nonealiasreturn9tuple[nodes.Import | nodes.ImportFrom | None, str | None]c                   |r| d| n|d}d}d}|j         D ]}|| u r|                                |                                 u r|j        | j        k    rAt          |t          j                  rDt          fd|j        D                       rd} n|j        D ]\  }	}
|
s|	|k    rd}d} n|r not          |t          j                  rR||j	        k    rG|j        D ];\  }	}
|j
         d|	 k    rd} n#|dk    r||	k    r|s|
sd} n|
s|	|k    rd}d} n<|r n|rt          j        ||           s||fS d	S )
zEReturn the node where [base.]<name> is imported or None if not found..NF
reimportedc              3  0   K   | ]}|d          k    V  dS )r   N ).0inamefullnames     K/var/www/piapp/venv/lib/python3.11/site-packages/pylint/checkers/imports.py	<genexpr>z$_get_first_import.<locals>.<genexpr>j   s,      AAE8uQx'AAAAAA    Tshadowed-import*NN)bodyscope
fromlineno
isinstancer   Importanynames
ImportFromrX   modnameastroidare_exclusive)rQ   rR   rT   rV   rX   rZ   firstfoundmsgimported_nameimported_aliasrd   s              @re   _get_first_importr{   U   s    $(1$THEE
C " "D==;;==DJJLL((U-=-O-OeU\** 	AAAAU[AAAAA 16  -~% -5*@*@ E+CE u/00 	##5:[  1M>em#E#Em#E#EEE $ M11!& 2*8 2 !%) mu.D.D $/ E W*5$77 cz:rg   rs   ignored_modulesSequence[str]boolc                    t          ||          rdS t          |           rdS t          | j        t          j                  rt          | j                  rdS t          | t                    S )NT)	r   r   rn   parentr   Ifr   r   ImportError)rQ   rs   r|   s      re   _ignore_import_failurer      sn    
 /22 t d## t$+ux(( \$+-F-F t!$444rg   mod_files_listItemsView[str, set[str]]_ImportTreec                8   i }| D ]\  }}|g g}|                     d          D ]=}t          |d         t                    sJ |d                             |i g f          }>t          |d         t                    sJ |d                             |           |S )zGet a list of 2-uple (module, list_of_files_which_import_this_module),
    it will return a dictionary to represent this as a tree.
    r^   r      )splitrn   dict
setdefaultlistextend)r   	tree_defsmodfilesrQ   prefixs         re   _make_tree_defsr      s      I$  
U/8"oiinn 	8 	8Fd1gt,,,,,7%%fr2h77DD$q'4(((((Qurg   data
indent_strc                0   g }|                                  }t          t          |d                     D ]\  }\  }\  }}|sdn%dd                    t          |                     d}||                    | d|            d	}	n>|                    | d
| d|            |t          |          dz
  k    r| d	}	n| d}	|r8t          |t                    r#|                    t          ||	                     d                    |          S )z3Return a string which represents imports as a tree.c                    | d         S )Nr   ra   )xs    re   <lambda>z!_repr_tree_defs.<locals>.<lambda>   s    aPQd rg   )key (,)N z  z\-r   z| 
)	items	enumeratesortedjoinappendlenrn   r   _repr_tree_defs)
r   r   linesnodes_itemsir   subr   
files_listsub_indent_strs
             re   r   r      sG   E**,,K"+F;NN,S,S,S"T"T ? ?C#u$HRR*Hchhve}}.E.E*H*H*H
LLC..*..///!NNLLZ==3====>>>C$$q((($.!2!2!2$.!2!2!2 	?:c4(( 	?LLn==>>>99Urg   filenamedep_infodict[str, set[str]]c                   i }t          t          j                            t          j                            |                     d         d          }|                    d           t          |                                          D ]Q\  }}t          |          }d||<   |                    |           |D ] }||vrd||<   |                    |           !Rt          |                                          D ]-\  }}t          |          D ]}|	                    ||           .|
                    |           S ),Write dependencies as a dot (graphviz) file.r   LR)rankdirzURL="." node[shape="box"]r   )r   ospathsplitextbasenameemitr   r   	emit_node	emit_edgegenerate)r   r   doneprinterrs   dependenciessorted_dependencies
depmodnames           re   _dependencies_graphr      sR   D))"'*:*:8*D*DEEaHRVWWWGLL,---!'(8(8!9!9 . .$\22W'"""- 	. 	.J%%#$Z !!*---	. %+8>>+;+;$<$< 3 3 
Ll++ 	3 	3Ggz2222	3H%%%rg   sectr   gtypeNonec                v    t          | |          }|                    t          | d| f                     dS )zaGenerate a dependencies graph and add some information about it in the
    report's section.
    z"imports graph has been written to N)r   r   r   )r   r   r   r   
outputfiles        re   _make_graphr      sD     %Xx88JKK	eSSzSSUVVWWWWWrg   E0401zUnable to import %simport-errorz4Used when pylint has been unable to import a module.	old_names)F0401zold-import-errorE0402)z2Attempted relative import beyond top-level packagerelative-beyond-top-levelzSUsed when a relative import tries to access too many levels in the current package.R0401)zCyclic import (%s)cyclic-importzBUsed when a cyclic import between two or more modules is detected.R0402)zUse 'from %s import %s' insteadconsider-using-from-importzEmitted when a submodule of a package is imported and aliased with the same name, e.g., instead of ``import concurrent.futures as futures`` use ``from concurrent import futures``.W0401)zWildcard import %swildcard-importz-Used when `from module import *` is detected.W0404)zReimport %r (imported line %s)r_   z.Used when a module is imported more than once.W0406)zModule import itselfimport-selfz'Used when a module is importing itself.W0407)z!Prefer importing %r instead of %rpreferred-modulez?Used when a module imported has a preferred replacement module.W0410)z:__future__ import is not the first non docstring statementmisplaced-futurezgPython 2.5 and greater require __future__ import to be the first non docstring statement in the module.C0410)z!Multiple imports on one line (%s)multiple-importszBUsed when import statement importing multiple modules is detected.C0411)z%s should be placed before %swrong-import-orderzvUsed when PEP8 import order is not respected (standard imports first, then third-party libraries, then local imports).C0412)z'Imports from package %s are not groupedungrouped-importsz.Used when imports are not grouped by packages.C0413)z5Import "%s" should be placed at the top of the modulewrong-import-positionz%Used when code and imports are mixed.C0414)z-Import alias does not rename original packageuseless-import-aliaszwUsed when an import alias is same as original package, e.g., using import numpy as numpy instead of import numpy as np.C0415)zImport outside toplevel (%s)import-outside-toplevelzwUsed when an import statement is used anywhere other than the module toplevel. Move this import to the top of the file.W0416)zShadowed %r (imported line %s)rh   zFUsed when a module is aliased with a name that shadows another import.z!dict[str, MessageDefinitionTuple]MSGSra   )enchantc                  B   e Zd ZdZdZi ej        eZdZ	de	ddddfd	e
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eddddfde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f
Zdqd&Zdrd'Zdsd)Zdrd*Zdtd,Zdud/Zdvd1Zdwd4Zdxd6Zdyd8Zdwd9Zdzd;ZexZxZxZxZxZxZZ d{d=Z!e!xZ"xZ#Z$dyd>Z%dyd?Z&d|dAZ'd}dDZ(e)d~dG            Z*ddJZ+ddPZ,ddRZ-ddUZ.ddWZ/ddYZ0d|dZZ1	 	 ddd`Z2ddgZ3ddhZ4ddjZ5e6dsdk            Z7e6dsdl            Z8ddnZ9ddoZ:d|dpZ;d[S )ImportsCheckerzBaseChecker for import statements.

    Checks for
    * external modules dependencies
    * relative / wildcard imports
    * cyclic imports
    * uses of deprecated modules
    * uses of modules instead of preferred modules
    importsra   zdeprecated-modulescsvz	<modules>zBDeprecated modules which should not be used, separated by a comma.)defaulttypemetavarhelpzpreferred-modulesz<module:preferred-module>z?Couples of modules and preferred modules, separated by a comma.zimport-graphr   r   z	<file.gv>zOutput a graph (.gv or any supported image format) of all (i.e. internal and external) dependencies to the given file (report RP0402 must not be disabled).zext-import-graphzOutput a graph (.gv or any supported image format) of external dependencies to the given file (report RP0402 must not be disabled).zint-import-graphzOutput a graph (.gv or any supported image format) of internal dependencies to the given file (report RP0402 must not be disabled).zknown-standard-libraryzYForce import order to recognize a module as part of the standard compatibility libraries.zknown-third-partyzJForce import order to recognize a module as part of a third party library.zallow-any-import-levelzNList of modules that can be imported at any level, not just the top level one.zallow-wildcard-with-allFynz<y or n>z8Allow wildcard imports from modules that define __all__.zallow-reexport-from-packagez:Allow explicit reexports by alias from a package __init__.linterr"   r[   r   c                   t          j        | |           t          t                    | _        g | _        d | _        i | _        t                      | _        dd| j	        fdd| j
        ff| _        t          t                    | _        d S )NRP0401zExternal dependenciesRP0402zModules dependencies graph)r   __init__r   setimport_graph_imports_stack_first_non_import_node_module_pkg_allow_any_import_level_report_external_dependencies_report_dependencies_graphreports_excluded_edges)selfr   s     re   r   zImportsChecker.__init__  s    T6***8CC8H8H<>&*# 	 25$.0RS3T5TU
 <Gs;K;Krg   c                   i | j         j        _        | j         j        | j         _        t          t                    | _        i | _        d| _        | j         j        j	        | _
        t          d | j         j        j        D                       | _        t	          | j         j        j                  | _        | j         j        j        | _        dS )4Called before visiting project (i.e set of modules).Fc              3  H   K   | ]}d |v |                     d           V  dS ):Nr   )rb   modules     re   rf   z&ImportsChecker.open.<locals>.<genexpr>  s@       &
 &
f}} LL}}}&
 &
rg   N)r   statsr   r   r   r   r   _current_module_packageconfigr|   _ignored_modulesr   preferred_modulesallow_any_import_levelr   allow_reexport_from_package_allow_reexport_packager  s    re   openzImportsChecker.open  s    )+& K-',,',$/3{/A/Q!% &
 &
+,>&
 &
 &
 "
 "

 (+4;+=+T'U'U$'+{'9'U$$$rg   defaultdict[str, set[str]]c                    t          j        | j                  }|D ](}||                             | j        |                    )|S N)copydeepcopyr   difference_updater  )r  filtered_graphrQ   s      re   #_import_graph_without_ignored_edgesz2ImportsChecker._import_graph_without_ignored_edges  sO    t'899" 	O 	OD4 2243G3MNNNNrg   c                    | j                             d          ra|                                 }t          |          }t	          ||          D ].}|                     dd                    |                     -dS dS )r  r   )verticesz -> )argsN)r   is_message_enabledr  r   r   add_messager   )r  graphr  cycles       re   closezImportsChecker.close  s    ;))/:: 	K<<>>EE{{H#EH=== K K  v{{57I7I JJJJ		K 	KK Krg   =tuple[defaultdict[str, set[str]], defaultdict[str, set[str]]]c                    | j                             d          r| j        | j        fS t	          t
                    t	          t
                    fS Nr   )r   r  r   r  r   r   r  s    re   get_map_datazImportsChecker.get_map_data  sH     ;))/:: 	=%t';<<C  +c"2"233rg   r   Clist[tuple[defaultdict[str, set[str]], defaultdict[str, set[str]]]]c                F   | j                             d          rt          t                    | _        t          t                    | _        |D ];}|\  }}| j                            |           | j                            |           <|                                  d S d S r%  )r   r  r   r   r   r  updater"  )r  r   r   	to_updater   excluded_edgess         re   reduce_map_datazImportsChecker.reduce_map_data  s    
 ;))/:: 	 +C 0 0D#.s#3#3D ! < <	(1%~!((///$++N;;;;JJLLLLL	 	rg   set[str]c                    t          | j        j        j                  }t                                          D ]*\  }}|t          j        k    r|                    |          }+|S )z*Callback returning the deprecated modules.)	r   r   r  deprecated_modulesDEPRECATED_MODULESr   sysversion_infounion)r  all_deprecated_modules
since_versmod_sets       re   r/  z!ImportsChecker.deprecated_modules  se     "%T[%7%J!K!K#5#;#;#=#= 	O 	OJS---)?)E)Eg)N)N&%%rg   rQ   nodes.Modulec                    |j         | _        dS )z<Store if current module is a package, i.e. an __init__ file.N)packager
  r  rQ   s     re   visit_modulezImportsChecker.visit_module  s    '+|$$$rg   nodes.Importc                   |                      |           |                     |           |                     |           d |j        D             }t	          |          dk    r+|                     dd                    |          |           |D ]}|                     ||           |                     ||           | 	                    ||          }t          |j        t          j                  r|                     |           t          |                                t          j                  r|                     ||           ||                     ||j                   dS )z+Triggered when an import statement is seen.c                    g | ]\  }}|S ra   ra   rb   rT   _s      re   
<listcomp>z/ImportsChecker.visit_import.<locals>.<listcomp>  s    000'$000rg   rI   r   , r  rQ   N)_check_reimport_check_import_as_rename_check_toplevelrq   r   r  r   check_deprecated_module_check_preferred_module_get_imported_modulern   r   r   Module_check_positionrl   _record_import_add_imported_modulerT   )r  rQ   rq   rT   imported_modules        re   visit_importzImportsChecker.visit_import  si   T"""$$T***T"""00TZ000u::??/dii6F6FTRRR 	B 	BD((t444((t444"77dCCO$+u|44 +$$T***$**,,55 ;##D/:::&%%dO,@AAAA	B 	Brg   nodes.ImportFromc                X   |j         }|                     ||          }t          ||          }|                     |           |                     |           |                     ||           |                     ||           |                     ||           |                     |           | 	                    |||j
                   |                     |           t          |j        t          j                  r|                     |           t          |                                t          j                  r|                     ||           |dS |j        D ]G\  }}|dk    r!|                     ||j         d|            ,|                     ||j                   HdS )z(Triggered when a from statement is seen.)r   rX   Nri   r^   )rs   rI  r   rE  _check_misplaced_futurerG  rH  _check_wildcard_imports_check_same_line_importsrD  rX   rF  rn   r   r   rJ  rK  rl   rL  rq   rM  rT   )r  rQ   r   rN  absolute_namerT   r@  s          re   visit_importfromzImportsChecker.visit_importfrom)  s   <33D(CC'h77$$T***$$T***$$T=999$$T8444$$T?;;;%%d+++THDJGGGT"""dk5<00 	'  &&&djjllEL11 	7o666"Fz 	F 	FGD!s{{))$?3G0P0P$0P0PQQQQ))$0DEEEE		F 	Frg   c                V   |                      |          \  }}}t                      }t                      }d }||z   |z   D ]\  }}	t          |t          j                  r|n|}
|	                    d          \  }}}|rd||k    r^||
v rZt          |          sKt          |j        t          j                  rt          |j                  s| 
                    d||           |}| j                            d|j                  s|
                    |           g | _        d | _        d S )Nr^   r   rQ   r  )_check_imports_orderr   rn   r   rr   	partitionr   r   r   r   r  r   r  rm   addr   r   )r  rQ   std_importsext_importsloc_imports
met_importmet_fromcurrent_packageimport_nodeimport_namemetr9  r@  s                re   leave_modulezImportsChecker.leave_moduleE  sW   040I0I$0O0O-[+  #uu
 UU(3k(AK(O 	 	$K(e6FGGW((ZC'11#66MGQ
V#w..sNN.{;; # {158<< # %[%788	 #   !4;W UUU%O;11#[%;   GGG &*###rg   gnodes.If | nodes.Expr | nodes.Comprehension | nodes.IfExp | nodes.Assign | nodes.AssignAttr | nodes.Tryc                   | j         rd S t          |j        t          j                  sd S t          |t          j                  r:t          |                    t          j        t          j	        f                    rd S t          |t          j
                  r"d |j        D             }t          |          rd S || _         d S )Nc                    g | ]P}t          |t          j                  o3|j                            d           o|j                            d           QS )__)rn   r   
AssignNamerT   
startswithendswith)rb   targets     re   rA  z@ImportsChecker.compute_first_non_import_node.<locals>.<listcomp>  sg         65#344 /K**400/K((..  rg   )r   rn   r   r   rJ  Tryrp   nodes_of_classro   rr   Assigntargetsall)r  rQ   valid_targetss      re   compute_first_non_import_nodez,ImportsChecker.compute_first_non_import_nodee  s      & 	F$+u|44 	FdEI&& 	3u/? @AA,
 ,
 	 FdEL)) 
	  #l	  M =!! &*###rg   <nodes.FunctionDef | nodes.While | nodes.For | nodes.ClassDefc                   | j         rd S t          |j                                        t          j                  sd S |}t          |j        t          j                  s&|j        }t          |j        t          j                  &t          |t          j        t          j        f          r:t          |	                    t          j
        t          j        f                    rd S || _         d S r  )r   rn   r   rl   r   rJ  r   rn  rp   ro  ro   rr   )r  rQ   roots      re   visit_functiondefz ImportsChecker.visit_functiondef  s     & 	F $+++--u|<< 	FT[%,77 	;D T[%,77 	 dUXuy122 	4&&e6F'GHHII &*###rg   c                    |j         }|dk    rT|                                }|r<t          |t          j                  r|j         dk    s|                     d|           d S d S )N
__future__r   rQ   )rs   previous_siblingrn   r   rr   r  )r  rQ   r   prevs       re   rR  z&ImportsChecker._check_misplaced_future  sz    <|##((**D D tU%566D;?<<;W;W$$%7d$CCCF $#rg   c                    d |j         D             }t          j        |          }|                                D ]*\  }}|dk    r|                     d|||j        f           +d S )Nc              3      K   | ]	\  }}|V  
d S r  ra   r?  s      re   rf   z:ImportsChecker._check_same_line_imports.<locals>.<genexpr>  s&      00'$000000rg   r   r_   rX  )rq   collectionsCounterr   r  rm   )r  rQ   rq   counterrT   counts         re   rT  z'ImportsChecker._check_same_line_imports  s|    00TZ000%e,,"==?? 	X 	XKD%qyy  Ddo?V WWW	X 	Xrg   r   c                    | j         rt| j                            d| j         j                  r,|                     d||                                           dS | j                            d|j        |           dS dS )zCheck `node` import or importfrom node position is correct.

        Send a message  if `node` comes before another instruction
        r   rX  N)r   r   r  rm   r  	as_stringadd_ignored_messager:  s     re   rK  zImportsChecker._check_position  s     & 
	{--')D)O  	   +$T^^=M=M !      //+T_d    
	 
	rg   importedmodnodenodes.Module | Nonec                L   t          |t          j                  r|j        }n|r|j        nd}|s,|j        d         d                             d          d         }t          |t          j                  r|j        pddk    rd|z   }| j        	                    ||f           dS )z'Record the package `node` imports from.Nr   r^   r   )
rn   r   rr   rs   rT   rq   r   rX   r   r   )r  rQ   r  importednames       re   rL  zImportsChecker._record_import  s     dE,-- 	M<LL3BL?//L 	::a=+11#66q9LdE,-- 	.4:?q2H2H -L""D,#788888rg   list[tuple[ImportNode, str]]r~   c                R     d |D             }t           fd|D                       S )Nc                    g | ]\  }}|S ra   ra   )rb   rb  r@  s      re   rA  z6ImportsChecker._is_fallback_import.<locals>.<listcomp>  s    ???#3K;???rg   c              3  B   K   | ]}t          j        |          V  d S r  )rt   ru   )rb   rb  rQ   s     re   rf   z5ImportsChecker._is_fallback_import.<locals>.<genexpr>  s0      WW7(d;;WWWWWWrg   )rp   )rQ   r   s   ` re   _is_fallback_importz"ImportsChecker._is_fallback_import  s<     @?w???WWWWwWWWWWWrg   _module_node_tuple[list[tuple[ImportNode, str]], list[tuple[ImportNode, str]], list[tuple[ImportNode, str]]]c                |   g }g }g }g }g }g }g }g }	t          | j        j                  }
| j        D ]\  }}|                    d          rd|                    d          d         z   }n|                    d          d         }t          |j        t          j	                   }| j        
                    d|j                   }|
                    |          }||f}|dv r|                    |           |p|p|	}|                     ||          r|rJ|sH|                     d|d|                     ||f           d|                     |||	          f           3|d	k    r|                    |           |                    |           |s9|s|                    |           n!| j                            d|j        |           |p|	}|rJ|sH|                     d|d
|                     ||f           d|                     d||	          f           |dk    r|                    |           |                    |           |s9|s|                    |           n!| j                            d|j        |           |	}|rJ|sH|                     d|d|                     ||f           d|                     dd|	          f           |dk    rU|                    ||f           |s<|s|	                    ||f           | j                            d|j        |           |||fS )zChecks imports of module `node` are grouped by category.

        Imports must follow this order: standard, 3rd party, local
        r^   r   r   r   >   FUTURESTDLIBzstandard import ""rX  
THIRDPARTYzthird party import "N
FIRSTPARTYzfirst party import "LOCALFOLDER)r    r   r  r   rk  r   rn   r   r   rJ  r  rm   place_moduler   r  r  _get_full_import_name_get_out_of_order_stringr  )r  r  r\  third_party_importsfirst_party_importsexternal_importslocal_importsthird_party_not_ignoredfirst_party_not_ignoredlocal_not_ignoredisort_driverrQ   rs   r9  nestedignore_for_import_orderimport_categorynode_and_package_importwrong_imports                      re   rY  z#ImportsChecker._check_imports_order  sN    57<><>9;68@B@B:<"4;#566!0 V	 V	MD'!!#&& 0c 2 21 55!--,,Q/#DK>>>F*.+*H*H$do+ + '# +77@@O'+Wo#"666""#:;;;+ ).)( 
 ++D,??   $$,!^0J0JDRY?0[0[^^^ 99 7 7 1  %    !L00#**+BCCC ''(?@@@ 2 /667NOOOO770$/4    7K:K 
 
$$,!a43M3MtU\o3^3^aaa 99 $&=?P  % 	 	 	 !L00#**+BCCC ''(?@@@ 2 /667NOOOO770$/4    1 
 
$$,!a43M3MtU\o3^3^aaa 99 $d,=  % 	 	 	 !M11$$dG_555 2 )00$AAAA770$/4   ,m;;rg   r  #list[tuple[ImportNode, str]] | Noner  r  rU   c           	         |rt          |          dk    rdnd}t          |          t          k    rd                     fd|d t          t          dz                     D                       dz   d                     fd|t          t           dz            d          D                       z   }n!d                     fd	|D                       }d
| d| }nd}|rt          |          dk    rdnd}t          |          t          k    rd                     fd|d t          t          dz                     D                       dz   d                     fd|t          t           dz            d          D                       z   }n!d                     fd|D                       }d| d| }nd}|rt          |          dk    rdnd}t          |          t          k    rd                     fd|d t          t          dz                     D                       dz   d                     fd|t          t           dz            d          D                       z   }n!d                     fd|D                       }d| d| }nd}|r|r|rdn	|s|rdndnd}	|r|r|rdndnd}
|r|rdndnd}|
 | }| |	 | | |r|nd }|S )Nr   sr   rB  c                B    g | ]}d                      |           d S r  r  rb   tpir  s     re   rA  z;ImportsChecker._get_out_of_order_string.<locals>.<listcomp>h  C        # C : :3 ? ?BBB  rg   rI   z (...) c                B    g | ]}d                      |           d S r  r  r  s     re   rA  z;ImportsChecker._get_out_of_order_string.<locals>.<listcomp>q  r  rg   c                B    g | ]}d                      |           d S r  r  r  s     re   rA  z;ImportsChecker._get_out_of_order_string.<locals>.<listcomp>{  B        ?D66s;;>>>  rg   zthird party importr   c                B    g | ]}d                      |           d S r  r  r  s     re   rA  z;ImportsChecker._get_out_of_order_string.<locals>.<listcomp>  r  rg   c                B    g | ]}d                      |           d S r  r  r  s     re   rA  z;ImportsChecker._get_out_of_order_string.<locals>.<listcomp>  r  rg   c                B    g | ]}d                      |           d S r  r  )rb   fpir  s     re   rA  z;ImportsChecker._get_out_of_order_string.<locals>.<listcomp>  r  rg   zfirst party importc                B    g | ]}d                      |           d S r  r  r  s     re   rA  z;ImportsChecker._get_out_of_order_string.<locals>.<listcomp>  r  rg   c                B    g | ]}d                      |           d S r  r  r  s     re   rA  z;ImportsChecker._get_out_of_order_string.<locals>.<listcomp>  r  rg   c                B    g | ]}d                      |           d S r  r  )rb   lir  s     re   rA  z;ImportsChecker._get_out_of_order_string.<locals>.<listcomp>  s3    SSSr:33B77:::SSSrg   zlocal importz and zand )r   r   r   int)r  r  r  r  pluralimports_listthird_partyfirst_partylocaldelimiter_third_partydelimiter_first_party1delimiter_first_party2delimiter_first_partyrx   s   `             re   r  z'ImportsChecker._get_out_of_order_string[  s     	 344q88SSbF&''*DDDII   ': F#&@A&E"F"F F(       ii   ': #%?$?1$D E E G G(    (  $yy   #6      GvFFFFKKK 	 344q88SSbF&''*DDDII   ': F#&@A&E"F"F F(       ii   ': #%?$?1$D E E G G(    (  $yy   #6      GvFFFFKKK 	..22SSF=!!$>>>II   '4 F#&@A&E"F"F F(       ii   '4 #%?$?1$D E E G G(    (  $yySSSS]SSS    ;6::L::EEE A$)A"-??ggRR  	 ;FMk5e5TT##2 	 ?J!QE"9&&rrr#9 S;Q S S (1 ((1(%uu2( ( 	 
rg   
importNodec                   	 |d         j          d|d         j        d         d          S # t          $ rI |d         j        d         d         }|d         }|                    d          d         |k    r|cY S |cY S w xY w)Nr   r^   r   )rs   rq   AttributeErrorr   )r  r  rQ   r9  s       re   r  z$ImportsChecker._get_full_import_name  s    	 !m+IIjm.A!.DQ.GIII 	 	 	"1+A.q1D%a=Gzz#q!W,, 
 NNN	s   (+ AA>9A>=A>
importnoders   c                   	 |                     |          S # t          j        $ r4 t          ||| j                  rY d S |                     d|           Y nt          j        $ r;}d|d|j         d}|                     d|j        |t                     Y d }~nd }~wt          j
        $ r | j                            d          sY d S t          ||| j                  rY d S | j        j        j        st          |          rY d S t!          ||          }|                     dt#          |          |	           Y nt$          $ r}t          j        |d }~ww xY wd S )
Nr   r{  zCannot import z	 due to ''zsyntax-error)liner  
confidencer   rC  )do_import_modulert   TooManyLevelsErrorr   r  r  AstroidSyntaxErrorerrorlinenor   AstroidBuildingErrorr   r  r  analyse_fallback_blocksr   r   repr	ExceptionAstroidError)r  r  rs   excmessagedotted_modnamees          re   rI  z#ImportsChecker._get_imported_module  s   	...w777) 	K 	K 	K%j'4;PQQ tt8zJJJJJ) 	 	 	GwGG39GGGGZ%6WQU          + 	Y 	Y 	Y;11.AA tt%j'4;PQQ ttK&>*:66 tt,ZAAN^$~2F2FZXXXXX 	. 	. 	.&A-	.tsD    %EEE'1B,EE% E5E?	EEEimportedmodnamec                   |                                 j        }|                                 j        }t          j                            t          j                            |                    d         }	 t          j        	                    ||          }n# t          $ r Y nw xY w||k    r|                     d|           d	S t          j                            |          s|dk    r-|| j        vr$|                    dd          d         | j        |<   | j        j        j        }|                    |t'                                }||vr|                    |           | j        |                             |           | j                            d|j                  rt1          |          r$| j        |                             |           d	S d	S d	S )
z8Notify an imported module, used to analyze dependencies.r   r   r{  r   r^   r   r   )r  N)rw  filerT   r   r   r   r   rt   modutilsget_module_partr   r  is_stdlib_moduler   rsplitr   r	  r   r   r   r[  r   r  r  r   r  )r  rQ   r  module_filecontext_namerV   dependencies_statimportedmodnamess           re   rM  z#ImportsChecker._add_imported_module  s   iikk&yy{{'w 0 0 = =>>qA	%.>> OO  	 	 	D	 ?**]66666!22?CC 	Hz!!l$:J&J&J 2>1D1DS!1L1LQ1O . 6:[5F5S0;;OSUUSS#333 $$\222 l+//@@@;11dk 2   H'--H $\266GGGGG%	H 	HH Hs   6 B 
B$#B$mod_pathc                   |gt          t          j        j        j                  rfdj        D             fd| j        D             }|r3|                     d| j        |d                  |d         f           dS dS )z0Check if the module has a preferred replacement.c                4    g | ]}j          d |d          S r^   r   )rs   rb   rT   rQ   s     re   rA  z:ImportsChecker._check_preferred_module.<locals>.<listcomp><  s-    NNN4dl66T!W66NNNrg   c                d    g | ],}D ]'}||k    s||                     d           d         v %|(-S r  r  )rb   kr   mod_compares      re   rA  z:ImportsChecker._check_preferred_module.<locals>.<listcomp>?  s]     
 
 
"
 
 CxxCIIcNN1%%%  &%%%rg   r   r   rX  N)rn   rt   r   node_classesrr   rq   r  r  )r  rQ   r  matchesr  s    `  @re   rH  z&ImportsChecker._check_preferred_module6  s      jdGM6ABB 	ONNNN4:NNNK
 
 
 
+
 
 
  	",WQZ8'!*E      	 	rg   c                   |j         }|D ]}t          |          s d S |d                             dd          }|d         }|d         }||k    rHt          |          dk    r0| j        du s	| j        du r|                     d|t                     t          |          d	k    r |                     d
||d         |f           d S )Nr   r^   r   )maxsplitFr   )rQ   r  rI   r   rX  )rq   rr  r  r   r  r
  r  r   )r  rQ   rq   rT   splitted_packagesrc  aliased_names          re   rE  z&ImportsChecker._check_import_as_renameQ  s   
 	 	Dt99  $QsQ ? ?+B/K7Ll**$%%**,55/588  !7dt TTTT&''1,,  0+A.< !   !	 	rg   Nr   rW   rX   rY   c           
        | j                             d          s| j                             d          sdS |                                }|                                }||fg}||ur|                    |df           |D ]\\  }}|j        D ]O\  }	}
t          |||	|||
          \  }}|1|/|dk    r|	n|
}	|                     |||	|j        ft                     P]dS )zDCheck if a module with the same name is already imported or aliased.r_   rh   N)rQ   r  r  )
r   r  framerw  r   rq   r{   r  rm   r   )r  rQ   r   rX   r  rw  contextsknown_contextknown_levelrT   rZ   rv   rx   s                re   rD  zImportsChecker._check_reimporti  s/    {--
 
 	+001BCC	 F

yy{{EN#uOOT4L)))*2 		 		&M;#z  e.-xe 
s $#&,#6#644ED$$$dE4D-ERV %   		 		rg   r   r   r@  r!   _dummyLinterStats | Nonec                    t          | j                                                  }|st                      t	          |          }|                    t          |                     dS )z5Return a verbatim layout for displaying dependencies.N)r   _external_dependencies_infor   r   r   r   r   )r  r   r@  r  r   tree_strs         re   r   z,ImportsChecker._report_external_dependencies  sa     #4#C#I#I#K#KLL 	%"$$$"8,,L**+++++rg   c                   | j         j        j        }|r3| j         j        j        s0| j         j        j        s| j         j        j        st                      | j         j        j        }|rt          |||d           | j         j        j        }|rt          || j	        |d           | j         j        j        }|rt          || j
        |d           dS dS )r   r   z	external z	internal N)r   r	  r   r  r   ext_import_graphint_import_graphr   r   r  _internal_dependencies_info)r  r   r@  r  r   r   s         re   r   z)ImportsChecker._report_dependencies_graph  s     ;$1 	%K+	%{!2	% {!2	%
 #$$$;%2 	6(D"555;%6 	W$"BD+VVV;%6 	W$"BD+VVVVV	W 	Wrg   internalc                0   t          t                    }| j        j        j                                        D ]]\  }}|D ]U}| j                            ||          }|                    |          }|r|s|s|s||         	                    |           V^|S )z4Build the internal or the external dependency graph.)
r   r   r   r	  r   r   r   getrk  r[  )r  r  r   importee	importersimporterr9  	is_insides           re   _filter_dependencies_graphz)ImportsChecker._filter_dependencies_graph  s    ,7,<,<#';#4#A#G#G#I#I 	2 	2Hi% 2 2*..xBB$//88	 2 2 28 2(O''111	2
 rg   c                .    |                      d          S )zYReturn cached external dependencies information or build and
        cache them.
        Fr  r  r  s    re   r  z*ImportsChecker._external_dependencies_info  s    
 ...>>>rg   c                .    |                      d          S )zYReturn cached internal dependencies information or build and
        cache them.
        Tr  r  r  s    re   r  z*ImportsChecker._internal_dependencies_info  s    
 ...===rg   rN  c                    |                                 j        rd S |                     |          }|j        D ]*\  }}|dk    r|s|                     d|j        |           +d S )Nri   r   rC  )rw  r9  _wildcard_import_is_allowedrq   r  rs   )r  rQ   rN  wildcard_import_is_allowedrT   r@  s         re   rS  z&ImportsChecker._check_wildcard_imports  s     99;; 	F%)%E%Eo%V%V"z 	R 	RGD!s{{#={  !2D QQQ	R 	Rrg   c                >    | j         j        j        o|d uod|j        v S )N__all__)r   r  allow_wildcard_with_alllocals)r  rN  s     re   r  z*ImportsChecker._wildcard_import_is_allowed  s/    K6 4t+4_33	
rg   c                    t                                          t          j                  rdS fdj        D             } fd|D             }|r-                     dd                    |                     dS dS )z=Check whether the import is made outside the module toplevel.Nc                x    g | ]6}t          t          j                  rj         d |d          n|d         7S r  )rn   r   rr   rs   r  s     re   rA  z2ImportsChecker._check_toplevel.<locals>.<listcomp>  s]     
 
 
  dE$4554<++$q'+++!W	
 
 
rg   c                &    g | ]}|j         v|S ra   )r   )rb   rT   r  s     re   rA  z2ImportsChecker._check_toplevel.<locals>.<listcomp>  s-     
 
 
T9U-U-UD-U-U-Urg   r   rB  rC  )rn   rl   r   rJ  rq   r  r   )r  rQ   module_namesscoped_importss   ``  re   rF  zImportsChecker._check_toplevel  s     djjllEL11 	F
 
 
 
 

 
 

 
 
 
)
 
 
  	)		.0I0IPT      	 	rg   r   r"   r[   r   )r[   r   )r[   r  )r[   r#  )r   r"   r   r'  r[   r   )r[   r-  )rQ   r7  r[   r   )rQ   r<  r[   r   )rQ   rP  r[   r   )rQ   rf  r[   r   )rQ   ru  r[   r   )rQ   r   r[   r   )rQ   r   r  r  r[   r   )rQ   r   r   r  r[   r~   )r  r7  r[   r  )r  r  r  r  r  r  r[   rU   )r  r   r[   rU   )r  r   rs   rU   r[   r  )rQ   r   r  rU   r[   r   )rQ   r   r  rU   r[   r   rj   )rQ   r   r   rW   rX   rY   r[   r   )r   r   r@  r!   r  r  r[   r   )r  r~   r[   r  )rQ   rP  rN  r  r[   r   )rN  r  r[   r~   )<__name__
__module____qualname____doc__rT   r   DEPRECATED_MODULE_MESSAGEr   msgsdefault_deprecated_modulesDEFAULT_PREFERRED_MODULESDEFAULT_STANDARD_LIBRARYDEFAULT_KNOWN_THIRD_PARTYoptionsr   r  r  r"  r&  r,  r/  r;  rO  rV  re  rt  	visit_tryvisit_assignattrvisit_assignvisit_ifexpvisit_comprehension
visit_exprvisit_ifrx  visit_classdef	visit_forvisit_whilerR  rT  rK  rL  staticmethodr  rY  r  r  rI  rM  rH  rE  rD  r   r   r  r   r  r  rS  r  rF  ra   rg   re   r   r   E  s         D@o7@4@D!# !5&)	 		
  46)	 		
 &9	 
	
 &9	 
	
 &9	 
	
 %3&8	 		
  4&)	 		
 %&) 	
 & %R	 	
 * %T	 	
hGTL L L LV V V V"   K K K K4 4 4 4   & & & &4 4 4 4B B B B2F F F F8+ + + +@#+ #+ #+ #+N 11I 1  1< 1+ 1@S 1+ + + +, 0A@N@Y   X X X X   &9 9 9 92 X X X \Xj< j< j< j<X| | | ||   2   @"H "H "H "HH   6   6  $ 	    :, , , ,W W W W*	 	 	 	 ? ? ? _? > > > _>
R 
R 
R 
R
 
 
 
     rg   r   r   r"   c                J    |                      t          |                      d S r  )register_checkerr   )r   s    re   registerr6    s$    
N62233333rg   )rQ   r   rR   rS   rT   rU   rV   rW   rX   rY   rZ   rW   r[   r\   )rQ   r   rs   rU   r|   r}   r[   r~   )r   r   r[   r   r  )r   r   r   rW   r[   rU   )r   rU   r   r   r[   rU   )
r   rU   r   r   r   r   r   rU   r[   r   r  )Fr!  rz  r   r  r  r   r1  r   collections.abcr   r   	functoolsr   typingr   r	   r
   r   r   rt   r   astroid.nodes._base_nodesr   pylint.checkersr   r   pylint.checkers.utilsr   r   r   r   r   r   pylint.constantsr   pylint.exceptionsr   pylint.graphr   r   pylint.interfacesr   pylint.reporters.ureports.nodesr   r   r   pylint.typingr   pylint.utilsr    pylint.utils.linterstatsr!   pylint.lintr"   rU   r   r0  r{   r   r   r   r   r   r   __annotations__r&  r'  r%  r   r6  ra   rg   re   <module>rG     s  
 ( ' ' " " " " " "      				 



 # # # # # # / / / / / / / / % % % % % % 8 8 8 8 8 8 8 8 8 8 8 8 8 8        0 0 0 0 0 0 8 8 8 8 8 8 8 8                8 7 7 7 7 7 . . . . . . / / / / / / / / " " " " " " L L L L L L L L L L 0 0 0 0 0 0 $ $ $ $ $ $ 0 0 0 0 0 0 %$$$$$$
 3d4S>2DI=>>? x(|()w}000{888777  " " J4 4 4 4n5 5 5 5*       (& & & &&X X X XZ+>	456	Z+  Z+  Z+$  %Z+4  5Z+>  ?Z+H  IZ+R  SZ+\  ]Z+h  iZ+r  sZ+~  Z+H  IZ+R  SZ+^  _Z+j  kZ+ Z Z Z Zz  (  d d d d d_k d d dN4 4 4 4 4 4rg   