
    c                       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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 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l+m,Z, ddl-m.Z. erddl/m0Z0 ee1eeee1ef                  ee1         f         f         Z2ddhdhdhdhdhh ddhh dh dh dd
Z3dqd#Z4drd/Z5dsd3Z6dtd7Z7dudvd:Z8dwd>Z9dxdC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<   djZ=dkZ>djZ? G dl dmee          Z@dydpZAdS )zz!Imports checkers for Python code.    )annotationsN)defaultdict)	ItemsViewSequence)TYPE_CHECKINGAnyDictListUnion)nodes)
ImportNode)BaseCheckerDeprecatedMixin)get_import_nameis_from_fallback_blockis_node_in_guarded_import_blockis_typing_guardnode_ignores_exception)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   )rE   rE   r   )rE      r   )rE      r   )rE      r   )rE      r   )rE   	   r   )rE   
   r   )rE      r   modname
str | Nonereturn	list[str]c                    | |                      d          ndfdt          t                              D             S )zSplit the names of the given module into subparts.

    For example,
        _qualified_names('pylint.checkers.ImportsChecker')
    returns
        ['pylint', 'pylint.checkers', 'pylint.checkers.ImportsChecker']
    N. c                P    g | ]"}d                      d|dz                      #S )rS   r      )join).0inamess     7lib/python3.11/site-packages/pylint/checkers/imports.py
<listcomp>z$_qualified_names.<locals>.<listcomp>Z   s2    BBB1CHHU1q1u9%&&BBB    )splitrangelen)rN   rZ   s    @r[   _qualified_namesra   Q   sH     #*=GMM#2EBBBBc%jj0A0ABBBBr]   noder   contextnodes.LocalsDictNodeNGnamestrbaselevel
int | Nonealias9tuple[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.rS   NF
reimportedc              3  0   K   | ]}|d          k    V  dS )r   N )rX   inamefullnames     r[   	<genexpr>z$_get_first_import.<locals>.<genexpr>r   s,      AAE8uQx'AAAAAAr]   Tshadowed-import*NN)bodyscope
fromlineno
isinstancer   ImportanyrZ   
ImportFromrh   rN   astroidare_exclusive)rb   rc   re   rg   rh   rj   firstfoundmsgimported_nameimported_aliasrq   s              @r[   _get_first_importr   ]   s
    $(1$THEE
C " "D= 	;;==DJJLL( 	U-=-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  $ M1 "' +9
 !%) mu.D  $/ E W*5$77 cz:r]   ignored_modulesSequence[str]boolc                    t          |          D ]	}||v r dS 
t          |           rdS t          | t                    S )NT)ra   r   r   ImportError)rb   rN   r   	submodules       r[   _ignore_import_failurer      s]    
 &g..  	' 	44	 't,,  t!$444r]   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.
    rS   r   rV   )r^   ry   dict
setdefaultlistextend)r   	tree_defsmodfilesrb   prefixs         r[   _make_tree_defsr      s      I$  
U/8"oiinn 	8 	8Fd1gt,,,,,7%%fr2h77DD$q'4(((((Qur]   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   ro   )xs    r[   <lambda>z!_repr_tree_defs.<locals>.<lambda>   s    aPQd r]   )keyrT   (,)N z  z\-rV   z| 
)	items	enumeratesortedrW   appendr`   ry   r   _repr_tree_defs)
r   r   linesnodes_itemsrY   r   subr   
files_listsub_indent_strs
             r[   r   r      sK   E**,,K"+F;NN,S,S,S"T"T ? ?C#u$HRR*Hchhve}}.E.E*H*H*H
 	3LLC..*..///!NNLLZ==3====>>>C$$q(( 3$.!2!2!2$.!2!2!2 	?:c4(( 	?LLn==>>>99Ur]   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"]rV   )r   ospathsplitextbasenameemitr   r   	emit_node	emit_edgegenerate)r   r   doneprinterrN   dependenciessorted_dependencies
depmodnames           r[   _dependencies_graphr      sT   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%%%r]   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        r[   _make_graphr      sD     %Xx88JKK	eSSzSSUVVWWWWWr]   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)rm   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)rs   zFUsed when a module is aliased with a name that shadows another import.z!dict[str, MessageDefinitionTuple]MSGSro   )enchantc                  N   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ded&Zdfd'Zdgd)Zdfd*Zdhd,Zdid/Zdjd1Zdkd3Zdid4Zdld6ZexZxZxZxZxZxZxZZdmd8Z e xZ!xZ"Z#dkd9Z$dkd:Z%dnd<Z&dod?Z'e(dpdB            Z)dqdEZ*drdIZ+dsdLZ,dtdNZ-dndOZ.	 	 dudvdTZ/dwd[Z0dwd\Z1dxd^Z2e3j4        j5        dgd_            Z6e3j4        j5        dgd`            Z7dydbZ8dzdcZ9dnddZ:dPS ){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
    importsro   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-graphrT   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   rP   r   c                    t          j        | |           t          t                    | _        g | _        d | _        i | _        t                      | _        dd| j	        fdd| j
        ff| _        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)selfr   s     r[   r   zImportsChecker.__init__  sy    T6***8CC8H8H<>&*#  	 25$.0RS3T5TU
r]   c                   i | j         j        _        | j         j        | j         _        t          t                    | _        i | _        d| _        t          t                    | _        | 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^   )rX   modules     r[   rr   z&ImportsChecker.open.<locals>.<genexpr>  sL       &
 &
f}&
LL&
 &
 &
 &
 &
 &
r]   N)r   statsr   r   r   r   r   _current_module_package_excluded_edgesconfigr   _ignored_modulesr   preferred_modulesallow_any_import_levelr   allow_reexport_from_package_allow_reexport_packager  s    r[   openzImportsChecker.open  s    )+& K-',,',$;Fs;K;K/3{/A/Q!% &
 &
+,>&
 &
 &
 "
 "

 (+4;+=+T'U'U$'+{'9'U$$$r]   defaultdict[str, set[str]]c                    t          j        | j                  }|D ](}||                             | j        |                    )|S N)copydeepcopyr   difference_updater  )r  filtered_graphrb   s      r[   #_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r]   c                    | j                             d          ra|                                 }t          |          }t	          ||          D ].}|                     dd                    |                     -dS dS )r  r   )verticesz -> )argsN)r   is_message_enabledr  r   r   add_messagerW   )r  graphr  cycles       r[   closezImportsChecker.close  s    ;))/:: 	K<<>>EE{{H#EH=== K K  v{{57I7I JJJJ		K 	KK Kr]   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       r[   r&  z!ImportsChecker.deprecated_modules  sh     "%T[%7%J!K!K#5#;#;#=#= 	O 	OJS-- O)?)E)Eg)N)N&%%r]   rb   nodes.Modulec                    |j         | _        dS )z<Store if current module is a package, i.e. an __init__ file.N)packager
  r  rb   s     r[   visit_modulezImportsChecker.visit_module  s    '+|$$$r]   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 ro   ro   rX   re   _s      r[   r\   z/ImportsChecker.visit_import.<locals>.<listcomp>  s    000'$000r]   rF   r   , r  rb   N)_check_reimport_check_import_as_rename_check_toplevelrZ   r`   r   rW   check_deprecated_module_check_preferred_module_get_imported_modulery   parentr   Module_check_positionrw   _record_import_add_imported_modulere   )r  rb   rZ   re   imported_modules        r[   visit_importzImportsChecker.visit_import  so   T"""$$T***T"""00TZ000u::? 	S/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r]   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   rh   Nrt   rS   )rN   r?  r   r;  _check_misplaced_futurer=  r>  _check_wildcard_imports_check_same_line_importsr:  rh   r<  ry   r@  r   rA  rB  rw   rC  rZ   rD  re   )r  rb   r   rE  absolute_namere   r7  s          r[   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{ F))$?3G0P0P$0P0PQQQQ))$0DEEEE		F 	Fr]   c                   |                      |          \  }}}t                      }t                      }d }||z   |z   D ]\  }}	t          |t          j                  r|n|}
|	                    d          \  }}}|r3||k    r-||
v r)t          |          du r|                     d||           |}| j        	                    d|j
                  s|
                    |           g | _        d | _        d S )NrS   Fr   rb   r  )_check_imports_orderr   ry   r   r|   	partitionr   r   r   r  rx   addr   r   )r  rb   std_importsext_importsloc_imports
met_importmet_fromcurrent_packageimport_nodeimport_namemetr0  r7  s                r[   leave_modulezImportsChecker.leave_module6  s:   040I0I$0O0O-[+  #uu
 UU(3k(AK(O 	 	$K(e6FGGW((ZC'11#66MGQV#w.V sNV 4K@@EI	V   !4;W UUU%O;11#[%;   GGG &*###r]   nodes.If | nodes.Expr | nodes.Comprehension | nodes.IfExp | nodes.Assign | nodes.AssignAttr | nodes.TryExcept | nodes.TryFinallyc                   | j         rd S t          j        t          j                  sd S t          j        t          j        g}fd|D             }|r:t                              t          j	        t          j
        f                    rd S t          t          j                  r"d j        D             }t          |          rd S | _         d S )Nc                4    g | ]}t          |          |S ro   )ry   )rX   allowedrb   s     r[   r\   z@ImportsChecker.compute_first_non_import_node.<locals>.<listcomp>f  s8     
 
 
Zg5N5N

 
 
r]   c                    g | ]P}t          |t          j                  o3|j                            d           o|j                            d           QS )__)ry   r   
AssignNamere   
startswithendswith)rX   targets     r[   r\   z@ImportsChecker.compute_first_non_import_node.<locals>.<listcomp>p  sg         65#344 /K**400/K((..  r]   )r   ry   r@  r   rA  	TryExcept
TryFinallyr{   nodes_of_classrz   r|   Assigntargetsall)r  rb   nested_allowedis_nested_allowedvalid_targetss    `   r[   compute_first_non_import_nodez,ImportsChecker.compute_first_non_import_nodeR  s     & 	F$+u|44 	F/5+;<
 
 
 
#1
 
 
  	u/? @AA"
 "
 	 FdEL)) 
	  #l	  M =!! &*###r]   <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        t          j        f          r:t          |
                    t          j        t          j        f                    rd S || _         d S r  )r   ry   r@  rw   r   rA  Ifrh  rg  r{   ri  rz   r|   )r  rb   roots      r[   visit_functiondefz ImportsChecker.visit_functiondef  s     & 	F $+++--u|<< 	FT[%,77 	;D T[%,77 	 dUXu'7IJJ 	4&&e6F'GHHII &*###r]   c                    |j         }|dk    rT|                                }|r<t          |t          j                  r|j         dk    s|                     d|           d S d S )N
__future__r   rb   )rN   previous_siblingry   r   r|   r   )r  rb   r   prevs       r[   rI  z&ImportsChecker._check_misplaced_future  s    <|# 		((**D D tU%566D;?<<;WD $$%7d$CCCF		 		r]   c                    d |j         D             }t          j        |          }|                                D ]*\  }}|dk    r|                     d|||j        f           +d S )Nc              3      K   | ]	\  }}|V  
d S r  ro   r6  s      r[   rr   z:ImportsChecker._check_same_line_imports.<locals>.<genexpr>  s&      00'$000000r]   rV   rm   rO  )rZ   collectionsCounterr   r   rx   )r  rb   rZ   counterre   counts         r[   rK  z'ImportsChecker._check_same_line_imports  s    00TZ000%e,,"==?? 	X 	XKD%qy X  Ddo?V WWW	X 	Xr]   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   rO  N)r   r   r  rx   r   	as_stringadd_ignored_messager1  s     r[   rB  zImportsChecker._check_position  s     & 
	{--')D)O  	   +$T^^=M=M !      //+T_d    
	 
	r]   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   rS   rV   )
ry   r   r|   rN   re   rZ   r^   rh   r   r   )r  rb   r  importednames       r[   rC  zImportsChecker._record_import  s     dE,-- 	M<LL3BL?//L 	::a=+11#66q9LdE,-- 	.4:?q2H 	. -L""D,#788888r]   list[tuple[ImportNode, str]]r   c                R     d |D             }t           fd|D                       S )Nc                    g | ]\  }}|S ro   ro   )rX   rY  r7  s      r[   r\   z6ImportsChecker._is_fallback_import.<locals>.<listcomp>  s    ???#3K;???r]   c              3  B   K   | ]}t          j        |          V  d S r  )r}   r~   )rX   rY  rb   s     r[   rr   z5ImportsChecker._is_fallback_import.<locals>.<genexpr>  s0      WW7(d;;WWWWWWr]   )r{   )rb   r   s   ` r[   _is_fallback_importz"ImportsChecker._is_fallback_import  s<     @?w???WWWWwWWWWWWr]   _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|rT|sR|                     d|d|                                 dd|d         d                                          df           =|d	k    r|                    |           |                    |           |s9|s|                    |           n!| j                            d|j        |           |p|	}|rT|sR|                     d|d
|                                 dd|d         d                                          df           |dk    r|                    |           |                    |           |s9|s|                    |           n!| j                            d|j        |           |	}|rT|sR|                     d|d|                                 dd|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
        rS   rV   r   r   >   FUTURESTDLIBzstandard import ""rO  
THIRDPARTYzthird party import "
FIRSTPARTYzfirst party import "LOCALFOLDER)r   r   r  r   rd  r^   ry   r@  r   rA  r  rx   place_moduler   r  r   r  r  )r  r  rS  third_party_importsfirst_party_importsexternal_importslocal_importsthird_party_not_ignoredfirst_party_not_ignoredlocal_not_ignoredisort_driverrb   rN   r0  nestedignore_for_import_orderimport_categorynode_and_package_importwrong_imports                      r[   rP  z#ImportsChecker._check_imports_order  sR    57<><>9;68@B@B:<"4;#566!0 M	 M	MD'!!#&& 0c 2 21 55!--,,Q/#DK>>>F*.+*H*H$do+ + '# +77@@O'+Wo#"66 B""#:;;;+ ).)( 
 ++D,??   $$,!C0@0@CCCAQ 2 < < > >AAA %    !L0 0#**+BCCC ''(?@@@ 2 /667NOOOO770$/4    7K:K  $$,!F4>>3C3CFFFAQ 2 < < > >AAA %    !L0 #**+BCCC ''(?@@@ 2 /667NOOOO770$/4    1  $$,!F4>>3C3CFFFAQ 2 < < > >AAA %    !M1 $$dG_555 2 )00$AAAA770$/4   ,m;;r]   
importnoderN   rO   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   rx  zCannot import z	 due to ''zsyntax-error)liner  
confidencer   r9  )do_import_moduler}   TooManyLevelsErrorr   r  r   AstroidSyntaxErrorerrorlinenor   AstroidBuildingErrorr   r  r  analyse_fallback_blocksr   r   repr	ExceptionAstroidError)r  r  rN   excmessagedotted_modnamees          r[   r?  z#ImportsChecker._get_imported_moduleJ  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importedmodnamerf   c                    |                                 j        }|                                 j        }t          j                            t          j                            |                    d         }	 t          j        	                    ||          }n# t          $ r Y nw xY wt          |j        t          j                  ot          |j                  }||k    r|                     d|           d	S t          j                            |          s|dk    r-|| j        vr$|                    dd          d         | j        |<   | j        j        j        }|                    |t1                                }||vr|                    |           | j        |                             |           | j                            d|j                  r|r$| j        |                             |           d	S d	S d	S )
z8Notify an imported module, used to analyze dependencies.r   r   rx  r   rS   rV   r   )r  N)rt  filere   r   r   r   r   r}   modutilsget_module_partr   ry   r@  r   rs  r   r   is_standard_moduler   rsplitr   r	  r   r   r   rR  r   r  r  r  )	r  rb   r  module_filecontext_namerg   in_type_checking_blockdependencies_statimportedmodnamess	            r[   rD  z#ImportsChecker._add_imported_modulej  s   iikk&yy{{'w 0 0 = =>>qA	%.>> OO  	 	 	D	 ",DK!B!B "
KH
 H
 ?* 	H]66666!44_EE 	Hz! Pl$:J&J P 2>1D1DS!1L1LQ1O . 6:[5F5S0;;OSUUSS#33 3 $$\222 l+//@@@K22?2UUH)H $\266GGGGG'	H 	HH Hs   6 B 
B$#B$mod_pathc                f    || j         v r'|                     d|| j         |         |f           dS dS )z0Check if the module has a preferred replacement.r   rO  N)r  r   )r  rb   r  s      r[   r>  z&ImportsChecker._check_preferred_module  sY    t-- 	",X6A      	 	r]   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   rS   rV   )maxsplitFr   )rb   r  rF   r   rO  )rZ   rl  r  r`   r  r
  r   r   )r  rb   rZ   re   splitted_packagesrZ  aliased_names          r[   r;  z&ImportsChecker._check_import_as_rename  s   
 	 	Dt99  $QsQ ? ?+B/K7Ll* $%%* 
,5
/58
   !7dt TTTT&''1,   0+A.< !   !	 	r]   Nr   rh   ri   c           
        | j                             d          s| j                             d          sdS |                    d          }|                                }||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.rm   rs   NT)future)rb   r  r  )
r   r  framert  r   rZ   r   r   rx   r   )r  rb   r   rh   r  rt  contextsknown_contextknown_levelre   rj   r   r   s                r[   r:  zImportsChecker._check_reimport  s<    {--
 
 	+001BCC	 F

$
''yy{{EN#u 	*OOT4L)))*2 		 		&M;#z  e.-xe 
s   #&,#6A44ED$$$dE4D-ERV %   		 		r]   r   r   r7  r   _dummyLinterStats | Nonec                    t          |                                                                           }|st                      t	          |          }|                    t          |                     dS )z5Return a verbatim layout for displaying dependencies.N)r   _external_dependencies_infor   r   r   r   r   )r  r   r7  r  r   tree_strs         r[   r   z,ImportsChecker._report_external_dependencies  sj     #4#C#C#E#E#K#K#M#MNN 	%"$$$"8,,L**+++++r]   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          || 	                                |d           | j         j        j        }|r&t          || 
                                |d           dS dS )r   rT   z	external z	internal N)r   r	  r   r  r   ext_import_graphint_import_graphr   r   r  _internal_dependencies_info)r  r   r7  r  r   r   s         r[   r  z)ImportsChecker._report_dependencies_graph  s     ;$1 	%K+	%{!2	% {!2	%
 #$$$;%2 	6(D"555;%6 	Y$"B"B"D"DdKXXX;%6 	Y$"B"B"D"DdKXXXXX	Y 	Yr]   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   getrd  rR  )r  r  r!  importee	importersimporterr0  	is_insides           r[   _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
 r]   c                .    |                      d          S )zYReturn cached external dependencies information or build and
        cache them.
        Fr  r  r  s    r[   r  z*ImportsChecker._external_dependencies_info  s    
 ...>>>r]   c                .    |                      d          S )zYReturn cached internal dependencies information or build and
        cache them.
        Tr  r  r  s    r[   r  z*ImportsChecker._internal_dependencies_info  s    
 ...===r]   rE  c                    |                                 j        rd S |                     |          }|j        D ]*\  }}|dk    r|s|                     d|j        |           +d S )Nrt   r   r9  )rt  r0  _wildcard_import_is_allowedrZ   r   rN   )r  rb   rE  wildcard_import_is_allowedre   r7  s         r[   rJ  z&ImportsChecker._check_wildcard_imports	  s     99;; 	F%)%E%Eo%V%V"z 	R 	RGD!s{ R#= R  !2D QQQ	R 	Rr]   c                >    | j         j        j        o|d uod|j        v S )N__all__)r   r  allow_wildcard_with_alllocals)r  rE  s     r[   r  z*ImportsChecker._wildcard_import_is_allowed  s/    K6 4t+4_33	
r]   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 )rS   r   )ry   r   r|   rN   )rX   re   rb   s     r[   r\   z2ImportsChecker._check_toplevel.<locals>.<listcomp>#  s]     
 
 
  $ 011t|''d1g'''a
 
 
r]   c                &    g | ]}|j         v|S ro   )r   )rX   re   r  s     r[   r\   z2ImportsChecker._check_toplevel.<locals>.<listcomp>+  s6     
 
 
T9U-U

 
 
r]   r   r8  r9  )ry   rw   r   rA  rZ   r   rW   )r  rb   module_namesscoped_importss   ``  r[   r<  zImportsChecker._check_toplevel  s     djjllEL11 	F
 
 
 
 
	
 
 

 
 
 
)
 
 
  	)		.0I0IPT      	 	r]   r   r   rP   r   )rP   r   )rP   r  )rP   r$  )rb   r.  rP   r   )rb   r3  rP   r   )rb   rG  rP   r   )rb   r]  rP   r   )rb   rq  rP   r   )rb   r   rP   r   )rb   r   r  r  rP   r   )rb   r   r   r  rP   r   )r  r.  rP   r  )r  r   rN   rO   rP   r  )rb   r   r  rf   rP   r   )rb   r   r  rf   rP   r   ru   )rb   r   r   rO   rh   ri   rP   r   )r   r   r7  r   r  r  rP   r   )r  r   rP   r  )rb   rG  rE  r  rP   r   )rE  r  rP   r   );__name__
__module____qualname____doc__re   r   DEPRECATED_MODULE_MESSAGEr   msgsdefault_deprecated_modulesDEFAULT_PREFERRED_MODULESDEFAULT_STANDARD_LIBRARYDEFAULT_KNOWN_THIRD_PARTYoptionsr   r  r  r#  r&  r2  rF  rM  r\  rp  visit_tryfinallyvisit_tryexceptvisit_assignattrvisit_assignvisit_ifexpvisit_comprehension
visit_exprvisit_ifru  visit_classdef	visit_forvisit_whilerI  rK  rB  rC  staticmethodr  rP  r?  rD  r>  r;  r:  r   r  r  r}   
decoratorscachedr  r  rJ  r  r<  ro   r]   r[   r   r   L  s         D@o7@4@D!# !5&)	 		
  46)	 		
 &9	 
	
 &9	 
	
 &9	 
	
 %3&8	 		
  4&)	 		
 %&) 	
 & %R	 	
 * %T	 	
hGT
 
 
 
V V V V$   K K K K& & & &4 4 4 4B B B B2F F F F8+ + + +8&+ &+ &+ &+` 7TT TT 	T
 	T 	T 	T )8+ + + +, 0A@N@Y   X X X X   &9 9 9 92 X X X \Xc< c< c< c<J   @'H 'H 'H 'HR      6  $ 	    :, , , ,Y Y Y Y*	 	 	 	 ? ? ? ? > > > >
R 
R 
R 
R
 
 
 
     r]   r   r   r   c                J    |                      t          |                      d S r  )register_checkerr   )r   s    r[   registerr  5  s$    
N62233333r]   )rN   rO   rP   rQ   )rb   r   rc   rd   re   rf   rg   rO   rh   ri   rj   rO   rP   rk   )rb   r   rN   rO   r   r   rP   r   )r   r   rP   r   r  )r   r   r   rO   rP   rf   )r   rf   r   r   rP   rf   )
r   rf   r   r   r   r   r   rf   rP   r   r  )Br  rw  r   r}  r  r   r(  r   collections.abcr   r   typingr   r   r	   r
   r   r}   r   astroid.nodes._base_nodesr   pylint.checkersr   r   pylint.checkers.utilsr   r   r   r   r   pylint.exceptionsr   pylint.graphr   r   pylint.interfacesr   pylint.reporters.ureports.nodesr   r   r   pylint.typingr   pylint.utilsr   pylint.utils.linterstatsr   pylint.lintr   rf   r   r'  ra   r   r   r   r   r   r   r   __annotations__r  r  r  r   r  ro   r]   r[   <module>r     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              / . . . . . / / / / / / / / " " " " " " 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	C 	C 	C 	C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  (  f f f f f_k f f fR4 4 4 4 4 4r]   