
    e>                       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$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l0m1Z1 erddl2m3Z3 ee4eeee4ef      ee4   f   f   Z5ddhdhdhdhdhh ddhh dh dh dd
Z6	 	 	 	 	 	 	 	 	 	 	 	 	 	 dQd Z7	 	 	 	 	 	 	 	 dRd!Z8dSd"Z9dTdUd#Z:dVd$Z;	 	 	 	 	 	 	 	 	 	 dWd%Z<i d&d'd(d)d*d+gifd,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIZ=dJe>dK<   dLZ?dMZ@dLZA G dN dOee      ZBdXdPZCy)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)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   )rG   rG   r   )rG      r   )rG      r   )rG      r   )rG      r   )rG   	   r   )rG   
   r   )rG      r   c                   |r| d| n|d}d}d}|j                   D ]   }|| u r	|j                         | j                         u r|j                  | j                  kD  rCt        |t        j
                        rIt        fd|j                  D              rd} n|j                  D ]  \  }	}
|
r	|	|k(  sd}d} n |s n~t        |t        j                        s||j                  k(  s|j                  D ]=  \  }	}
|j                   d|	 k(  rd} n"|dk7  r||	k(  r|s|
sd} n|
r3|	|k(  s9d}d} n |s! n |rt        j                  ||       s||fS y	)
zEReturn the node where [base.]<name> is imported or None if not found..NF
reimportedc              3  .   K   | ]  }|d    k(    yw)r   N ).0inamefullnames     9/usr/lib/python3/dist-packages/pylint/checkers/imports.py	<genexpr>z$_get_first_import.<locals>.<genexpr>i   s     AE8uQx'As   Tshadowed-import*NN)bodyscope
fromlineno
isinstancer   Importanynames
ImportFromlevelmodnameastroidare_exclusive)nodecontextnamebasere   aliasfirstfoundmsgimported_nameimported_aliasrW   s              @rX   _get_first_importrs   T   s}    $($qTHEE
C "D=;;=DJJL(U-=-=-OeU\\*AU[[AA16 -~%-5*@ E+C	
 u//0#5:[[ 1M>emm_Am_#EE $ M1!&. $)mu.D $/ E"F W**5$7cz    c                    t        ||      ryt        |       ryt        | j                  t        j
                        rt        | j                        ryt        | t              S )NT)	r   r   r`   parentr   Ifr   r   ImportError)ri   rf   ignored_moduless      rX   _ignore_import_failurerz      sK    
 /2 d#$++uxx(\$++-F!$44rt   c                    i }| D ]t  \  }}|g g}|j                  d      D ].  }t        |d   t              sJ |d   j                  |i g f      }0 t        |d   t              sJ |d   j                  |       v |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.
    rQ   r      )splitr`   dict
setdefaultlistextend)mod_files_list	tree_defsmodfilesri   prefixs         rX   _make_tree_defsr      s      I$ 
U/8"oiin 	8Fd1gt,,,7%%fr2h7D	8 $q'4(((Qu rt   c                   g }| j                         }t        t        |d             D ]  \  }\  }\  }}|sdnddj                  t        |             d}||j	                  | d|        d}	n5|j	                  | d	| d|        |t        |      d
z
  k(  r| d}	n| d}	|st        |t              s|j	                  t        ||	              dj                  |      S )z3Return a string which represents imports as a tree.c                    | d   S )Nr   rT   )xs    rX   <lambda>z!_repr_tree_defs.<locals>.<lambda>   s    aPQd rt   )key (,) z  z\-r|   z| 
)	items	enumeratesortedjoinappendlenr`   r~   _repr_tree_defs)
data
indent_strlinesnodes_itemsir   subr   
files_listsub_indent_strs
             rX   r   r      s    E**,K"+F;N,S"T ?C#u$RAchhve}.E-Fa*H
LLC5*./!NLLZL3%q=>C$q(($.<r!2$.<r!2:c4(LLn=>? 99Urt   c                ,   i }t        t        j                  j                  t        j                  j	                  |             d   d      }|j                  d       t        |j                               D ]H  \  }}t        |      }d||<   |j                  |       |D ]  }||vsd||<   |j                  |        J t        |j                               D ]'  \  }}t        |      D ]  }|j                  ||        ) |j                  |       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)filenamedep_infodoneprinterrf   dependenciessorted_dependencies
depmodnames           rX   _dependencies_graphr      s   D))"''*:*:8*DEaHRVWGLL,-!'(8!9 .$\2W'"- 	.J%#$Z !!*-	.	. %+8>>+;$< 3 
Ll+ 	3Ggz2	33 H%%rt   c                \    t        | |      }|j                  t        | d| f             y)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   sectgtype
outputfiles        rX   _make_graphr      s0     %Xx8JKK	eW$FzlSUVWrt   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)rR   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)rZ   zFUsed when a module is aliased with a name that shadows another import.z!dict[str, MessageDefinitionTuple]MSGSrT   )enchantc                     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dCd"ZdDd#ZdEd$ZdDd%Z	 	 dFd&Z	 	 	 	 	 	 dGd'ZdHd(ZdId)ZdJd*ZdKd+ZdId,Z	 	 	 	 dLd-ZexZxZxZxZxZxZZ 	 	 	 	 dMd.Z!e!xZ"xZ#Z$dKd/Z%dKd0Z&dNd1Z'	 	 	 	 	 	 dOd2Z(e)	 	 	 	 	 	 dPd3       Z*	 	 	 	 dQd4Z+	 	 	 	 	 	 dRd5Z,dSd6Z-dTd7Z.dNd8Z/	 	 dU	 	 	 	 	 	 	 dVd:Z0	 	 	 	 	 	 	 	 dWd;Z1	 	 	 	 	 	 	 	 dWd<Z2dXd=Z3e4dEd>       Z5e4dEd?       Z6	 	 	 	 	 	 dYd@Z7dZdAZ8dNdBZ9y9)[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
    importsrT   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__.c                   t        j                  | |       t        t              | _        g | _        d | _        i | _        t               | _        dd| j                  fdd| j                  ff| _        t        t              | _        y )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)selflinters     rX   r   zImportsChecker.__init__  s    T6*8CC8H<>&*#  	 25$.0R0RS3T5T5TU
 <Gs;Krt   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                  | _        y)4Called before visiting project (i.e set of modules).Fc              3  F   K   | ]  }d |v r|j                  d         yw):N)r}   )rU   modules     rX   rY   z&ImportsChecker.open.<locals>.<genexpr>  s(      &
f} LL&
s   !N)r   statsr   r   r   r   r   _current_module_packageconfigry   _ignored_modulesr~   preferred_modulesallow_any_import_levelr   allow_reexport_from_package_allow_reexport_packager   s    rX   openzImportsChecker.open  s    )+& KK--',',$/3{{/A/A/Q/Q!% &
++,,>>&
 "

 (+4;;+=+=+T+T'U$'+{{'9'9'U'U$rt   c                    t        j                  | j                        }|D ]#  }||   j                  | j                  |          % |S N)copydeepcopyr   difference_updater   )r   filtered_graphri   s      rX   #_import_graph_without_ignored_edgesz2ImportsChecker._import_graph_without_ignored_edges  sK    t'8'89" 	OD4 2243G3G3MN	Ort   c                    | j                   j                  d      rP| j                         }t        |      }t	        ||      D ]$  }| j                  ddj                  |             & yy)r   r   )verticesz -> )argsN)r   is_message_enabledr  r   r   add_messager   )r   graphr  cycles       rX   closezImportsChecker.close  sd    ;;))/:<<>EE{H#EH= K  v{{57I JK ;rt   c                    | j                   j                  d      r| j                  | j                  fS t	        t
              t	        t
              fS Nr   )r   r  r   r   r   r   r  s    rX   get_map_datazImportsChecker.get_map_data  sB     ;;))/:%%t';';<<C +c"233rt   c                0   | j                   j                  d      r{t        t              | _        t        t              | _        |D ]=  }|\  }}| j                  j                  |       | j
                  j                  |       ? | j                          y y r  )r   r  r   r   r   r   updater  )r   r   r   	to_updater  excluded_edgess         rX   reduce_map_datazImportsChecker.reduce_map_data  s    
 ;;))/: +C 0D#.s#3D ! <	(1%~!!((/$$++N;<
 JJL ;rt   c                    t        | j                  j                  j                        }t        j                         D ]*  \  }}|t        j                  k  s|j                  |      }, |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       rX   r  z!ImportsChecker.deprecated_modules  se     "%T[[%7%7%J%J!K#5#;#;#= 	OJS---)?)E)Eg)N&	O &%rt   c                &    |j                   | _        y)z<Store if current module is a package, i.e. an __init__ file.N)packager   r   ri   s     rX   visit_modulezImportsChecker.visit_module  s    '+||$rt   c                   | j                  |       | j                  |       | j                  |       |j                  D cg c]  \  }}|	 }}}t	        |      dk\  r#| j                  ddj                  |      |       |D ]  }| j                  ||       | j                  ||       | j                  ||      }t        |j                  t        j                        r| j                  |       t        |j                         t        j                        r| j!                  ||       || j#                  ||j$                          yc c}}w )z+Triggered when an import statement is seen.rH   r   , r  ri   N)_check_reimport_check_import_as_rename_check_toplevelrc   r   r  r   check_deprecated_module_check_preferred_module_get_imported_moduler`   rv   r   Module_check_positionr^   _record_import_add_imported_modulerk   )r   ri   rk   _rc   imported_modules         rX   visit_importzImportsChecker.visit_import  s   T"$$T*T"%)ZZ0'$00u:?/dii6FTR 	BD((t4((t4"77dCO$++u||4$$T*$**,5##D/:&%%dO,@,@A	B	 1s   Ec                   |j                   }| j                  ||      }t        ||      }| j                  |       | j	                  |       | j                  ||       | j                  ||       | j                  ||       | j                  |       | j                  |||j                         | j                  |       t        |j                  t        j                        r| j!                  |       t        |j#                         t        j                        r| j%                  ||       |y|j&                  D ]H  \  }}|dk7  r"| j)                  ||j*                   d|        -| j)                  ||j*                         J y)z(Triggered when a from statement is seen.)r   re   Nr[   rQ   )rf   r1  r   r-  _check_misplaced_futurer/  r0  _check_wildcard_imports_check_same_line_importsr,  re   r.  r`   rv   r   r2  r3  r^   r4  rc   r5  rk   )r   ri   r   r7  absolute_namerk   r6  s          rX   visit_importfromzImportsChecker.visit_importfrom(  sO   <<33D(C'h7$$T*$$T*$$T=9$$T84$$T?;%%d+THDJJGT"dkk5<<0  &djjlELL1o6"zz 	FGD!s{))$?3G3G2H$0PQ))$0D0DE		Frt   c                6   | j                  |      \  }}}t               }t               }d }||z   |z   D ]  \  }}	t        |t        j                        r|n|}
|	j                  d      \  }}}|ra||k7  r\||
v rXt        |      sMt        |j                  t        j                        rt        |j                        s| j                  d||       |}| j                  j                  d|j                        s|
j                  |        g | _        d | _        y )NrQ   r   ri   r  )_check_imports_orderr   r`   r   rd   	partitionr   rv   rw   r   r  r   r  r_   addr   r   )r   ri   std_importsext_importsloc_imports
met_importmet_fromcurrent_packageimport_nodeimport_namemetr&  r6  s                rX   leave_modulezImportsChecker.leave_moduleD  s   040I0I$0O-[+  #u
 U(3k(AK(O 	$K(e6F6FG(ZC'11#6MGQ#w.sN.{;{11588<$[%7%78   !4;W U%O;;11#[%;%; GGG'	* !&*#rt   c                H   | j                   ry t        |j                  t        j                        sy t        |t        j
                        r9t        |j                  t        j                  t        j                  f            ry t        |t        j                        rw|j                  D cg c]V  }t        |t        j                        xr8 |j                  j                  d      xr |j                  j                  d      X }}t!        |      ry || _         y c c}w )N__)r   r`   rv   r   r2  Tryrb   nodes_of_classra   rd   Assigntargets
AssignNamerk   
startswithendswithall)r   ri   targetvalid_targetss       rX   compute_first_non_import_nodez,ImportsChecker.compute_first_non_import_noded  s     &&$++u||4dEII&3u/?/? @A,
 dELL) #ll	  65#3#34 /KK**40/KK((./M  =!&*#s   .ADc                   | j                   ry t        |j                  j                         t        j
                        sy |}t        |j                  t        j
                        s1|j                  }t        |j                  t        j
                        s1t        |t        j                  t        j                  f      r9t        |j                  t        j                  t        j                  f            ry || _         y r  )r   r`   rv   r^   r   r2  rw   rP  rb   rQ  ra   rd   )r   ri   roots      rX   visit_functiondefz ImportsChecker.visit_functiondef  s     && $++++-u||<T[[%,,7;;D T[[%,,7 dUXXuyy124&&e6F6F'GHI&*#rt   c                    |j                   }|dk(  rO|j                         }|r<t        |t        j                        r|j                   dk(  s| j                  d|       y y )N
__future__r   ri   )rf   previous_siblingr`   r   rd   r  )r   ri   r   prevs       rX   r:  z&ImportsChecker._check_misplaced_future  s]    <<|#((*D tU%5%564<<<;W$$%7d$C $rt   c                    d |j                   D        }t        j                  |      }|j                         D ]+  \  }}|dkD  s| j	                  d|||j
                  f       - y )Nc              3  &   K   | ]	  \  }}|  y wr  rT   )rU   rk   r6  s      rX   rY   z:ImportsChecker._check_same_line_imports.<locals>.<genexpr>  s     0'$0s   r|   rR   r@  )rc   collectionsCounterr   r  r_   )r   ri   rc   counterrk   counts         rX   r<  z'ImportsChecker._check_same_line_imports  s`    0TZZ0%%e,"==? 	XKD%qy  Ddoo?V W	Xrt   c                   | j                   r{| j                  j                  d| j                   j                        r#| j	                  d||j                                y| j                  j                  d|j                  |       yy)zCheck `node` import or importfrom node position is correct.

        Send a message  if `node` comes before another instruction
        r   r@  N)r   r   r  r_   r  	as_stringadd_ignored_messager'  s     rX   r3  zImportsChecker._check_position  sw     &&{{--')D)D)O)O   +$T^^=M !  //+T__d 'rt   c                \   t        |t        j                        r|j                  }n|r|j                  nd}|s$|j
                  d   d   j                  d      d   }t        |t        j                        r|j                  xs ddk\  rd|z   }| j                  j                  ||f       y)z'Record the package `node` imports from.Nr   rQ   r|   )
r`   r   rd   rf   rk   rc   r}   re   r   r   )r   ri   importedmodnodeimportednames       rX   r4  zImportsChecker._record_import  s     dE,,-<<L3B?//L::a=+11#6q9LdE,,-4::?q2H -L""D,#78rt   c                `     |D cg c]  \  }}|	 }}}t         fd|D              S c c}}w )Nc              3  J   K   | ]  }t        j                  |        y wr  )rg   rh   )rU   rJ  ri   s     rX   rY   z5ImportsChecker._is_fallback_import.<locals>.<genexpr>  s     W7((d;Ws    #)rb   )ri   r   rJ  r6  s   `   rX   _is_fallback_importz"ImportsChecker._is_fallback_import  s4     8??#3K;??WwWWW @s   *c           	     F   g }g }g }g }g }g }g }g }	t        | j                  j                        }
| j                  D ]  \  }}|j	                  d      rd|j                  d      d   z   }n|j                  d      d   }t        |j                  t        j                         }| j                  j                  d|j                         }|
j                  |      }||f}|dv rv|j                  |       |xs |xs |	}| j                  ||      r|s|r| j                  d|d|j!                          dd|d   d   j!                          df       |d	k(  r|j                  |       |j                  |       |s;|s|j                  |       n'| j                  j#                  d|j                  |       |xs |	}|s|r| j                  d|d
|j!                          dd|d   d   j!                          df       |dk(  r|j                  |       |j                  |       |s;|s|j                  |       n'| j                  j#                  d|j                  |       |	}|s=|rA| j                  d|d|j!                          dd|d   d   j!                          df       |dk(  s|j                  ||f       |r|s|	j                  ||f       | j                  j#                  d|j                  |        |||fS )zChecks imports of module `node` are grouped by category.

        Imports must follow this order: standard, 3rd party, local
        rQ   r|   r   r   >   FUTURESTDLIBzstandard import ""r@  
THIRDPARTYzthird party import "
FIRSTPARTYzfirst party import "LOCALFOLDER)r   r   r   r   rU  r}   r`   rv   r   r2  r  r_   place_moduler   rq  r  rj  rk  )r   _module_noderD  third_party_importsfirst_party_importsexternal_importslocal_importsthird_party_not_ignoredfirst_party_not_ignoredlocal_not_ignoredisort_driverri   rf   r&  nestedignore_for_import_orderimport_categorynode_and_package_importwrong_imports                      rX   rA  z#ImportsChecker._check_imports_order  sb    57<><>9;68@B@B:<"4;;#5#56!00 M	MD'!!#&c 21 55!--,Q/#DKK>>F*.++*H*H$doo+ '# +77@O'+Wo#"66""#:;+ ).)( 
 ++D,?$$,!/0@/ACQ 2 < < >?qA %  !L0#**+BC ''(?@2/667NO770$//4  7K:K$$,!24>>3C2DAFQ 2 < < >?qA %  !L0#**+BC ''(?@2/667NO770$//4  1$$,!24>>3C2DAFQ 2 < < >?qA %  !M1$$dG_52)00$A770$//4WM	\ ,m;;rt   c                   	 |j                  |      S # t        j                  $ r/ t        ||| j                        rY y | j                  d|       Y y t        j                  $ r@}d|d|j                   d}| j                  d|j                  |t               Y d }~y d }~wt        j                  $ r | j                  j                  d      sY y t        ||| j                        rY y | j                  j                  j                  st        |      rY y t!        ||      }| j                  dt#        |      |	       Y y t$        $ r}t        j&                  |d }~ww xY w)
Nr   r`  zCannot import z	 due to ''zsyntax-error)liner  
confidencer   r+  )do_import_modulerg   TooManyLevelsErrorrz   r   r  AstroidSyntaxErrorerrorlinenor   AstroidBuildingErrorr   r  r   analyse_fallback_blocksr   r   repr	ExceptionAstroidError)r   
importnoderf   excmessagedotted_modnamees          rX   r1  z#ImportsChecker._get_imported_moduleU  sO   	...w77)) 	K%j'4;P;PQ8zJ, + )) 	&wk399+QGGZ%6%6WQU   &  ++ 	Y;;11.A%j'4;P;PQKK&&>>*:6,ZAN^$~2FZX   	.&&A-	.sD    *E#E#E#&6B!!1E#E#-+E#)E#E#EE#c                   |j                         j                  }|j                         j                  }t        j                  j                  t        j                  j                  |            d   }	 t        j                  j                  ||      }||k(  r| j                  d|       y	t        j                  j                  |      s|dk7  r0|| j                  vr"|j                  dd      d   | j                  |<   | j                  j                   j"                  }|j%                  |t'                     }||vr|j)                  |       | j*                  |   j)                  |       | j                  j-                  d|j.                        rt1        |      r| j2                  |   j)                  |       y	y	y	# t        $ r Y 9w xY w)
z8Notify an imported module, used to analyze dependencies.r   r   r`  r   rQ   r|   r   )r  N)r\  filerk   r   r   r   r   rg   modutilsget_module_partrx   r  is_stdlib_moduler   rsplitr   r   r   r   r   rC  r   r  r  r   r   )r   ri   importedmodnamemodule_filecontext_namerl   dependencies_statimportedmodnamess           rX   r5  z#ImportsChecker._add_imported_moduleu  s   iik&&yy{''ww 0 0 =>qA	%..>>O ?*]6!!22?Cz!l$:J:J&J 2>1D1DS!1LQ1O  . 6:[[5F5F5S5S0;;OSUS#33 $$\2 l+//@;;11dkk 2 '-$$\266G .# D  		s   5 G 	GGc           	        |g}t        |t        j                  j                  j                        r+|j
                  D cg c]  }|j                   d|d     }}| j                  D cg c]&  }|D ]  }||k(  s||j                  d      d   v r|! ( }}}|r*| j                  d|| j                  |d      |d   f       yyc c}w c c}}w )z0Check if the module has a preferred replacement.rQ   r   r   r@  N)
r`   rg   r   node_classesrd   rc   rf   r   r}   r  )r   ri   mod_pathmod_comparerk   kr   matchess           rX   r0  z&ImportsChecker._check_preferred_module  s      jdGMM66AABCG::N4dll^1T!WI6NKN
 ++
"
 CxCIIcN1%% 

 
 ",,WQZ8'!*E    O
s    C,+Cc                f   |j                   }|D ]  }t        |      s y |d   j                  dd      }|d   }|d   }||k7  r6t        |      dk(  r5| j                  du s| j
                  du r| j                  d|t               yt        |      d	k(  s| j                  d
||d   |f        y )Nr   rQ   r|   )maxsplitFr   )ri   r  rH   r   r@  )rc   rW  r  r   r  r   r  r   )r   ri   rc   rk   splitted_packagesrK  aliased_names          rX   r-  z&ImportsChecker._check_import_as_rename  s    

 	Dt9 $QsQ ?+B/K7Ll*$%*,,5//58  !7dt T&'1,  0+A.< ! !	rt   Nc           
        | j                   j                  d      s| j                   j                  d      sy|j                         }|j                         }||fg}||ur|j	                  |df       |D ]`  \  }}|j
                  D ]L  \  }	}
t        |||	|||
      \  }}|||dk(  r|	n|
}	| j                  |||	|j                  ft               N b y)zDCheck if a module with the same name is already imported or aliased.rR   rZ   N)ri   r  r  )
r   r  framer\  r   rc   rs   r  r_   r   )r   ri   r   re   r  r\  contextsknown_contextknown_levelrk   rm   rn   rp   s                rX   r,  zImportsChecker._check_reimport  s     {{--
++001BC

yy{EN#uOOT4L)*2 		&M;#zz e.-xe
s $#&,#64ED$$$dE4D4D-ERV % 		rt   c                    t        | j                  j                               }|s
t               t	        |      }|j                  t        |             y)z5Return a verbatim layout for displaying dependencies.N)r   _external_dependencies_infor   r   r   r   r   )r   r   r6  _dummyr   tree_strs         rX   r   z,ImportsChecker._report_external_dependencies  sD     #4#C#C#I#I#KL"$$"8,L*+rt   c                f   | j                   j                  j                  }|r`| j                   j                  j                  sJ| 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       yy)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   r6  r  r   r   s         rX   r   z)ImportsChecker._report_dependencies_graph  s     ;;$$11KK++{{!!22{{!!22"$$;;%%22(D"5;;%%66$"B"BD+V;;%%66$"B"BD+V rt   c                4   t        t              }| j                  j                  j                  j                         D ]W  \  }}|D ]M  }| j                  j                  ||      }|j                  |      }|r|s|r7|r:||   j                  |       O Y |S )z4Build the internal or the external dependency graph.)
r   r   r   r   r   r   r   getrU  rC  )r   internalr  importee	importersimporterr&  	is_insides           rX   _filter_dependencies_graphz)ImportsChecker._filter_dependencies_graph  s    ,7,<#';;#4#4#A#A#G#G#I 	2Hi% 2**..xB$//8	8(O''1	2	2 rt   c                &    | j                  d      S )zYReturn cached external dependencies information or build and
        cache them.
        Fr  r  r  s    rX   r  z*ImportsChecker._external_dependencies_info  s    
 ...>>rt   c                &    | j                  d      S )zYReturn cached internal dependencies information or build and
        cache them.
        Tr  r  r  s    rX   r  z*ImportsChecker._internal_dependencies_info  s    
 ...==rt   c                    |j                         j                  ry | j                  |      }|j                  D ],  \  }}|dk(  s|r| j	                  d|j
                  |       . y )Nr[   r   r+  )r\  r&  _wildcard_import_is_allowedrc   r  rf   )r   ri   r7  wildcard_import_is_allowedrk   r6  s         rX   r;  z&ImportsChecker._check_wildcard_imports!  sd     99;%)%E%Eo%V"zz 	RGD!s{#=  !2D Q	Rrt   c                n    | j                   j                  j                  xr |d uxr d|j                  v S )N__all__)r   r   allow_wildcard_with_alllocals)r   r7  s     rX   r  z*ImportsChecker._wildcard_import_is_allowed-  s:    KK66 4t+4_333	
rt   c                   t        |j                         t        j                        ry|j                  D cg c]5  }t        |t        j
                        r|j                   d|d    n|d   7 }}|D cg c]  }|| j                  vs| }}|r$| j                  ddj                  |      |       yyc c}w c c}w )z=Check whether the import is made outside the module toplevel.NrQ   r   r   r*  r+  )
r`   r^   r   r2  rc   rd   rf   r   r  r   )r   ri   rk   module_namesscoped_importss        rX   r.  zImportsChecker._check_toplevel4  s     djjlELL1 

	
  $ 0 01 ||nAd1gY'a
 
 *
T9U9U-UD
 
 )		.0IPT   

s   :B98B>B>r   r!   returnNone)r  r  )r  defaultdict[str, set[str]])r  z=tuple[defaultdict[str, set[str]], defaultdict[str, set[str]]])r   r!   r   zClist[tuple[defaultdict[str, set[str]], defaultdict[str, set[str]]]]r  r  )r  zset[str])ri   nodes.Moduler  r  )ri   znodes.Importr  r  )ri   nodes.ImportFromr  r  )ri   zgnodes.If | nodes.Expr | nodes.Comprehension | nodes.IfExp | nodes.Assign | nodes.AssignAttr | nodes.Tryr  r  )ri   z<nodes.FunctionDef | nodes.While | nodes.For | nodes.ClassDefr  r  )ri   r   r  r  )ri   r   rm  nodes.Module | Noner  r  )ri   r   r   zlist[tuple[ImportNode, str]]r  bool)rz  r  r  z_tuple[list[tuple[ImportNode, str]], list[tuple[ImportNode, str]], list[tuple[ImportNode, str]]])r  r   rf   strr  r  )ri   r   r  r  r  r  )ri   r   r  r  r  r  r\   )ri   r   r   
str | Nonere   
int | Noner  r  )r   r   r6  r    r  zLinterStats | Noner  r  )r  r  r  r  )ri   r  r7  r  r  r  )r7  r  r  r  ):__name__
__module____qualname____doc__rk   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(  r8  r>  rM  rZ  	visit_tryvisit_assignattrvisit_assignvisit_ifexpvisit_comprehension
visit_exprvisit_ifr]  visit_classdef	visit_forvisit_whiler:  r<  r3  r4  staticmethodrq  rA  r1  r5  r0  r-  r,  r   r   r  r   r  r  r;  r  r.  rT   rt   rX   r   r   D  s    D@o77@4@D!# !5&)			
  46)			
 &9	
	
 &9	
	
 &9	
	
 %3&8			
  4&)			
 %&)	
 & %R		
 * %T		
hGTLV"K4	F4 R 
	&4B2F8+@!+!+ 
!+R 7TTI TT 	T
 	T 	T )8+P+	+, 0A@N@YX&99 -9 
	92 XX#?X	X Xc<(c<
c<J$/2	@"HH66  $ 	  	
 
:,, +,5G,	,WW +W5GW	W*	 ? ? > >
R$
R7J
R	
R
rt   r   c                8    | j                  t        |              y r  )register_checkerr   )r   s    rX   registerr  M  s    
N623rt   )ri   r   rj   znodes.LocalsDictNodeNGrk   r  rl   r  re   r  rm   r  r  z9tuple[nodes.Import | nodes.ImportFrom | None, str | None])ri   r   rf   r  ry   zSequence[str]r  r  )r   zItemsView[str, set[str]]r  _ImportTreer  )r   r  r   r  r  r  )r   r  r   dict[str, set[str]]r  r  )
r   r  r   r  r   r   r   r  r  r  r  )Dr  r_  r   re  r  r   r  r   collections.abcr   r   	functoolsr   typingr   r	   r
   r   r   rg   r   astroid.nodes._base_nodesr   pylint.checkersr   r   pylint.checkers.utilsr   r   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!   r  r  r  rs   rz   r   r   r   r   r   __annotations__r  r  r  r   r  rT   rt   rX   <module>r	     s  
 ( "   	 
 # / % 8 8   0 8  / / " L L 0 $ 0$
 3d4S>2DI=>>? x(|()w}0{87" J4
4#4 4 	4
 4 4 ?4n5
55 #5 
	5*(&&XX0X8?XHK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  (  F_k FR4rt   