+
    f4j[;                    X   ^ RI Ht ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	 ^ RI
Ht ^ RIHt ^ RIHt ^ RIHt ^ RIHt R	t]'       d   ^ R
IHtHtHtHt RR.RR.RRR./tR R lt ! R R4      t ! R R4      t ! R R]4      t]! RR7       ! R R4      4       t ! R R4      t R# )     )annotationsN)
FileFinder)StringIO)contextmanager)	dataclass)chain)	TokenInfoF)AnyIterableIteratorMappingcollectionsabcospathzxml.parsers.expaterrorsmodelc                   V ^8  d   QhRR/# )   returnModuleCompleter )formats   "+lib/python3.14/_pyrepl/_module_completer.py__annotate__r      s     < < <    c                     \        R R/R7      # )__package__N)	namespace)r   r   r   r   make_default_module_completerr       s    mT%:;;r   c                      ] tR t^$tRtRR R lltR R ltR R ltR	 R
 ltR R lt	R R lt
R R ltR R ltR R ltR R ltR R lt]R R l4       tRtR# )r   a$  A completer for Python import statements.

Examples:
    - import <tab>
    - import foo<tab>
    - import foo.<tab>
    - import foo as bar, baz<tab>

    - from <tab>
    - from foo<tab>
    - from foo import <tab>
    - from foo import bar<tab>
    - from foo import (bar as baz, qux<tab>
Nc                    V ^8  d   QhRRRR/# )r   r   zMapping[str, Any] | Noner   Noner   )r   s   "r   r   ModuleCompleter.__annotate__4   s     C C": Cd Cr   c                	    T;'       g    / V n         . V n        \        P                  R ,          V n        \
        P                  P                  \        P                  ^ ,          4      V n	        R# )NNNN)
r   _global_cachesysr   _curr_sys_pathr   dirname	importlib__path___stdlib_path)selfr   s   &&r   __init__ModuleCompleter.__init__4   sG    "b79),!GGOOI,>,>q,ABr   c                    V ^8  d   QhRRRR/# )r   linestrr   zlist[str] | Noner   )r   s   "r   r   r$   :   s     
 
C 
,< 
r   c                    \        V4      P                  4       pV'       g   R#  V P                  ! V!  #   \         d    . u # i ; i)z7Return the next possible import completions for 'line'.N)ImportParserparsecomplete	Exception)r.   r2   results   && r   get_completionsModuleCompleter.get_completions:   sE    d#))+	==&)) 	 I	s   5 AAc               $    V ^8  d   QhRRRRRR/# )r   	from_name
str | Nonenamer   	list[str]r   )r   s   "r   r   r$   F   s!     2 2* 2J 29 2r   c                	d   VfK   Vf   Q hV P                  V4      w  r4V P                  W44      pV Uu. uF  q`P                  W64      NK  	  up# VfE   V P                  V4      w  r4V P                  W44      pV Uu. uF  q`P                  W64      NK  	  up# V P                  W4      # u upi u upi N)get_path_and_prefixfind_modulesformat_completion)r.   r=   r?   r   prefixmodulesmodules   &&&    r   r7   ModuleCompleter.completeF   s    ###33D9LD''5GGNOwV**48wOO<33I>LD''5GGNOwV**48wOO   11 P Ps   B(;B-c               $    V ^8  d   QhRRRRRR/# r   r   r3   rF   r   r@   r   )r   s   "r   r   r$   W   s!     > > >c >i >r   c                    V P                  W4      pV Uu. uF  qDP                  4       '       g   K  VNK  	  up# u upi )z7Find all modules under 'path' that start with 'prefix'.)_find_modulesisidentifier)r.   r   rF   rG   mods   &&&  r   rD   ModuleCompleter.find_modulesW   s7    $$T2  '=w*:*:*<w===s   ;;c               $    V ^8  d   QhRRRRRR/# rK   r   )r   s   "r   r   r$   ^   s&     ,B ,B# ,Bs ,By ,Br   c                	  a  V'       g   \         P                   Uu. uF  pS P                  W24      '       g   K  VNK   	  ppS P                   Uu. uF3  pS P                  VP                  V4      '       g   K'  VP                  NK5  	  pp\        WF,           4      # VP                  R 4      '       d4   S P                  P                  RR4      pS P                  W4      pVf   . # S P                  p\         P                  P                  VP                  R 4      ^ ,          4      p	V	'       ds   V	P                  p
V
'       d]   V Uu. uFO  pVP                  V
P                  8X  g   K   VP                  P                  VP                  R4      V
8X  g   KM  VNKQ  	  ppM. pRpVP                  R 4       F  pV Uu. uF,  pVP                  '       g   K  VP                  V8X  g   K*  VNK.  	  ppVf;   \         ;QJ d    V 3R lV 4       F  '       d   K   RM	  RM! V 3R lV 4       4      pS P#                  V4      pK  	  V Uu. uF  qUP                  NK  	  ppV'       d&   VP%                  \&        P                  VR4      4       V Uu. uF  pS P                  VV4      '       g   K  VNK!  	  up# u upi u upi u upi u upi u upi u upi ).r    Nc              3  F   <"   T F  pSP                  V4      x  K  	  R # 5irB   )_is_stdlib_module).0mod_infor.   s   & r   	<genexpr>0ModuleCompleter._find_modules.<locals>.<genexpr>   s"      'ELD**844Ws   !FTr   )r(   builtin_module_namesis_suggestion_matchglobal_cacher?   sorted
startswithr   getresolve_relative_namerG   split__spec__module_finder	find_specispkgalliter_submodulesextendHARDCODED_SUBMODULES)r.   r   rF   r?   builtin_modulesrH   third_party_modulespackagerG   imported_modulespecrO   is_stdlib_importsegmentrX   module_namesmodule_names   f&&              r   rM   ModuleCompleter._find_modules^   s   030H0H J0H"&":":4"H  $t0HO J=A=N=N #U=N6&*&>&>v{{F&S $/6;;=N #U/?@@??3nn((;G--d<D|	040A0A++//$**S/!*<= #++D*1 T'3!hh$))3 "00::388TJdR 3' T (,zz#G07 GH"..  -5]]g-E  xG G'#&3 'EL'333 'EL' $  **73G ' 3::'': 4 8 8r BC/; B|++K@ | B 	BQJ#U$TG ;BsL   J5J5$J:9J:J?)(J?J?;KK'KK	K,Kc                    V ^8  d   QhRRRR/# )r   module_infozpkgutil.ModuleInfor   boolr   )r   s   "r   r   r$      s     I I-? ID Ir   c                	    \        VP                  \        4      ;'       d$    VP                  P                  V P                  8H  # rB   )
isinstancerd   r   r   r-   )r.   rv   s   &&r   rV   !ModuleCompleter._is_stdlib_module   s>    ;44jA H H--22d6G6GG	Ir   c               $    V ^8  d   QhRRRRRR/# )r   rs   r3   rF   r   rw   r   )r   s   "r   r   r$      s!     / /s /C /D /r   c                	`    V'       d   VP                  V4      # VP                  R 4      '       * # )_)r_   )r.   rs   rF   s   &&&r   r\   #ModuleCompleter.is_suggestion_match   s,    ))&11 ))#...r   c                    V ^8  d   QhRRRR/# )r   parent_moduleslist[pkgutil.ModuleInfo]r   zIterator[pkgutil.ModuleInfo]r   )r   s   "r   r   r$      s     6 6.F 6Kg 6r   c                   V Uu. uF<  q"P                   '       g   K  VP                  P                  VP                  R4      NK>  	  pp\	        \
        P                  ! R V 4       4      4      p\        P                  ! V4      # u upi )z8Iterate over all submodules of the given parent modules.Nc              3  N   "   T F  q'       g   K  \        VR . 4      x  K  	  R# 5i)submodule_search_locationsN)getattr)rW   ro   s   & r   rY   2ModuleCompleter.iter_submodules.<locals>.<genexpr>   s(      3
 <GD6;;s   	%%)	rf   rd   re   r?   setr   from_iterablepkgutiliter_modules)r.   r   infospecssearch_locationss   &&   r   rh   ModuleCompleter.iter_submodules   s     ,;+Tzz ?##--dii>+ 	 ;u22 3
3
  
  ##$455;s
   B*Bc                    V ^8  d   QhRRRR/# )r   dotted_namer3   r   ztuple[str, str]r   )r   s   "r   r   r$      s      s  r   c                *   RV9  d   RV3# VP                  R4      '       d\   VP                  R4      pR\        V4      \        V4      ,
          ,          pRV9  d   W23# VP                  R^4      w  rEW4,           V3# VP                  R^4      w  rEWE3# )z
Split a dotted name into an import path and a
final prefix that is to be completed.

Examples:
    'foo.bar' -> 'foo', 'bar'
    'foo.' -> 'foo', ''
    '.foo' -> '.', 'foo'
rS   rT   )r_   lstriplenrsplit)r.   r   strippeddotsr   rF   s   &&    r   rC   #ModuleCompleter.get_path_and_prefix   s     k!{?"!!#&&"))#.H#k*S]:;D("~%#??32LD;&&"))#q1|r   c               $    V ^8  d   QhRRRRRR/# )r   r   r3   rH   r   r   )r   s   "r   r   r$      s!     " "c "3 "3 "r   c                	X    VR 8X  g   VP                  R4      '       d   V V 2# V RV 2# )rT   rS   )endswith)r.   r   rH   s   &&&r   rE   !ModuleCompleter.format_completion   s7    2:s++VF8$$q!!r   c               $    V ^8  d   QhRRRRRR/# )r   r?   r3   rm   r   r>   r   )r   s   "r   r   r$      s!     2 2# 2 2
 2r   c                    ^ pV F  pVR8w  d    MV^,          pK  	  VP                  RV^,
          4      p\        V4      V8  d   R# V^ ,          pWR pV'       d   V RV 2# T# )zpResolve a relative module name to an absolute name.

Example: resolve_relative_name('.foo', 'bar') -> 'bar.foo'
rS   N)r   r   )r.   r?   rm   level	characterbitsbases   &&&    r   ra   %ModuleCompleter.resolve_relative_name   sv     ICQJE  ~~c519-t9uAwF|#'$q1T1r   c                   V ^8  d   QhRR/# )r   r   r   r   )r   s   "r   r   r$      s     " "6 "r   c                    V P                   '       d    V P                  \        P                  8w  d@   \        P                  R,          V n        \	        \
        P                  ! 4       4      V n         V P                   # )zGlobal module cacher&   )r'   r)   r(   r   listr   r   r.   s   &r   r]   ModuleCompleter.global_cache   sS     !!!T%8%8CHH%D"%((1+D!%g&:&:&<!=D!!!r   )r)   r'   r-   r   rB   )__name__
__module____qualname____firstlineno____doc__r/   r:   r7   rD   rM   rV   r\   rh   rC   rE   ra   propertyr]   __static_attributes__r   r   r   r   r   $   sV    C
2">,B\I/6,"
2$ " "r   r   c                  .   ] tR t^tRt]P                  ]P                  ]P                  ]P                  ]P                  ]P                  0t0 RmtR R ltR R ltR R ltR R	 ltR
 R ltR R ltR R ltR R ltR R ltR R ltR R ltRtR# )r5   aE  
Parses incomplete import statements that are
suitable for autocomplete suggestions.

Examples:
    - import foo          -> Result(from_name=None, name='foo')
    - import foo.         -> Result(from_name=None, name='foo.')
    - from foo            -> Result(from_name='foo', name=None)
    - from foo import bar -> Result(from_name='foo', name='bar')
    - from .foo import (  -> Result(from_name='.foo', name='')

Note that the parser works in reverse order, starting from the
last token in the input string. This makes the parser more robust
when parsing multiple statements.
c                    V ^8  d   QhRRRR/# )r   coder3   r   r#   r   )r   s   "r   r   ImportParser.__annotate__   s     / /S /T /r   c                	   Wn         . p \        P                  ! \        V4      P                  4       F1  pVP
                  V P                  9  g   K   VP                  V4       K3  	  \        VRRR1,          4      V n        R#   \        P                   d   pR \        T4      9  d   . p Rp?LHRp?i\         d    . p LZi ; i)zunexpected EOFN)r   tokenizegenerate_tokensr   readlinetype_ignored_tokensappend
TokenErrorr3   SyntaxError
TokenQueuetokens)r.   r   r   tes   &&   r   r/   ImportParser.__init__   s    		--htn.E.EF66!5!55MM!$ G !". "" 	s1v-
  	F	s*   AB B CB00C=CCc                   V ^8  d   QhRR/# )r   r   z$tuple[str | None, str | None] | Noner   )r   s   "r   r   r      s     ' '; 'r   c                	f    V P                  4       ;p'       g   R # VP                  VP                  3# rB   )_parser=   r?   )r.   ress   & r   r6   ImportParser.parse   s)    {{}$$}}chh&&r   c                   V ^8  d   QhRR/# )r   r   zResult | Noner   )r   s   "r   r   r     s     ' ' 'r   c                	D   V P                   P                  4       ;_uu_ 4        V P                  4       uuR R R 4       #   + '       g   i     M; iT P                   P                  4       ;_uu_ 4        T P                  4       uuR R R 4       #   + '       g   i     R # ; irB   )r   
save_stateparse_from_importparse_importr   s   &r   r   ImportParser._parse  s^    [[##%%))+ &%%%[[##%%$$& &%%%s   >A	3BB	c                   V ^8  d   QhRR/# r   r   Resultr   )r   s   "r   r   r   
  s     ) )f )r   c                	   V P                   P                  4       P                  R 4      '       d.   V P                   P                  R4      '       d   \        RR7      # V P                  P                  R4      '       d   RpM<V P                   P                  R4      '       d   \        R4      hV P                  4       pVP                  R4      '       d   \        R4      hV P                  P                  R4      '       d-   V P                  P                  4        V P                  4        KM  V P                  P                  R 4      '       d   \        VR7      # \        R4      h)import rT   )r?   ,r   rS   )r   rstripr   r   r   peek_string
ParseErrorparse_dotted_namer_   popparse_dotted_as_name)r.   r?   s   & r   r   ImportParser.parse_import
  s    99&&x00TYY5G5G5L5Lr?";;""3''Dyy!!#&& 00))+D??3^,,kk%%c**KKOO%%';;""8,,t$$((r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r     s     6 66 6r   c                	   V P                   P                  4       pVP                  R 4      '       d=   V P                   P                  R4      '       d   \        V P	                  4       RR7      # VP                  R4      '       d.   V P                   P                  R4      '       d   \        RR7      # V P
                  P                  R4      '       g"   V P
                  P                  R4      '       d   \        V P	                  4       RR7      # V P                   P                  R4      '       d   \        R4      hV P                  4       pR	V9   d(   V P
                  P                  R4       \        VR7      # V P
                  P                  R4      '       d   \        VR7      # V P	                  4       p\        W2R7      # )
r   r   rT   )r=   r?   from)r=   (r   r   rS   )
r   r   r   r   parse_empty_from_importr   r   r   r   
pop_string)r.   r   r?   r=   s   &   r   r   ImportParser.parse_from_import  sJ   99##%X&&499+=+=c+B+BD$@$@$BLLV$$););C)@)@B'';;""3''4;;+B+B3+G+GD$@$@$BLL99c""011%%'$;KK""6*D));;""6**D))002		55r   c                   V ^8  d   QhRR/# r   r   r3   r   )r   s   "r   r   r   /  s     ! ! !r   c                	d   V P                   P                  R 4      '       d+   V P                   P                  4        V P                  4        V P                   P                  R4      '       d   V P                   P                  4        V P                   P	                  R4       V P                  4       # )r   r   r   )r   r   r   parse_as_namesr   
parse_fromr   s   &r   r   $ImportParser.parse_empty_from_import/  ss    ;;""3''KKOO!;;""3''KKOOx(  r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r   8  s      C r   c                	\    V P                  4       pV P                  P                  R 4       V# )r   )r   r   r   )r.   r=   s   & r   r   ImportParser.parse_from8  s(    **,	v&r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r   =  s     , ,c ,r   c                	N   V P                   P                  4        V P                   P                  R 4      '       d   V P                   P                  4        V P                   P	                  4       ;_uu_ 4        V P                  4       uuRRR4       #   + '       g   i     R# ; iasN)r   pop_namer   r   r   r   r   s   &r   r   !ImportParser.parse_dotted_as_name=  sc    ;;""4((KKOO[[##%%))+ &%%%s   8BB$	c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r   D  s     # #3 #r   c                	L   . pV P                   P                  R 4      '       d,   VP                  R 4       V P                   P                  4        V P                   P	                  4       '       dg   V P                   P                  4       ;p'       dE   VP                  V P                  9  d*   VP                  V P                   P                  4       4       V'       g   \        R4      hV P                   P                  R 4      '       d   VP                  R 4       V P                   P                  4        V P                   P	                  4       '       di   V P                   P                  4       ;p'       dG   VP                  V P                  9  d,   VP                  V P                   P                  4       4       K   V P                   P                  R 4      '       d.   VP                  R 4       V P                   P                  4        KN  RP                  VRRR1,          4      # )rS   r   rT   Nr   )r   r   r   r   	peek_namepeekstring	_keywordsr   r   join)r.   r?   toks   &  r   r   ImportParser.parse_dotted_nameD  se   ;;""3''KKKKOOKK!!##((***

$..0KK,,./011kk%%c**KKKKOO%%'' KK,,..S.JJdnn4DKK0023kk%%c**KKKKOOwwtDbDz""r   c                   V ^8  d   QhRR/# r   r   r#   r   )r   s   "r   r   r   ^  s     ! ! !r   c                	    V P                  4        V P                  P                  R 4      '       d-   V P                  P                  4        V P                  4        KM  R# )r   N)parse_as_namer   r   r   r   s   &r   r   ImportParser.parse_as_names^  sB    kk%%c**KKOO  +r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r   d  s     # #t #r   c                	    V P                   P                  4        V P                   P                  R 4      '       d7   V P                   P                  4        V P                   P                  4        R# R# r   )r   r   r   r   r   s   &r   r   ImportParser.parse_as_named  sJ    ;;""4((KKOOKK  " )r   )r   r   N>   r   r   r   )r   r   r   r   r   tokenINDENTDEDENTCOMMENTNLNEWLINE	ENDMARKERr   r   r/   r6   r   r   r   r   r   r   r   r   r   r   r   r   r   r5   r5      sy      	ellEMM%--O )I/$'
')$6&!
,#4!# #r   r5   c                      ] tR tRtRtR# )r   ik  r   N)r   r   r   r   r   r   r   r   r   r   k  s    r   r   T)frozenc                  4    ] tR tRt$ RtR]R&   RtR]R&   RtR# )r   io  Nr>   r=   r?   r   )r   r   r   r   r=   __annotations__r?   r   r   r   r   r   r   o  s     Iz D*r   r   c                      ] tR tRtRtR R lt]R R l4       tR R ltR	 R
 lt	R R lt
R R ltR R ltR R ltR R ltRtR# )r   iu  z@Provides helper functions for working with a sequence of tokens.c                    V ^8  d   QhRRRR/# )r   r   zlist[TokenInfo]r   r#   r   )r   s   "r   r   TokenQueue.__annotate__x  s     # # #4 #r   c                	.    Wn         ^ V n        . V n        R# )r   N)r   indexstack)r.   r   s   &&r   r/   TokenQueue.__init__x  s    '-
 "
r   c                   V ^8  d   QhRR/# )r   r   r
   r   )r   s   "r   r   r  ~  s      C r   c              #  	   "    V P                   P                  V P                  4       R x  V P                   P                  4        R #   \         d$    T P                   P                  4       T n         R # i ; i5irB   )r  r   r  r   r   r   s   &r   r   TokenQueue.save_state}  sU     	JJdjj) JJNN  	*)DJ	*s'   A:)A	 A:	*A73A:6A77A:c                   V ^8  d   QhRR/# r   r   rw   r   )r   s   "r   r   r    s     - -$ -r   c                	F    V P                   \        V P                  4      8  # rB   )r  r   r   r   s   &r   __bool__TokenQueue.__bool__  s    zzC,,,r   c                   V ^8  d   QhRR/# )r   r   zTokenInfo | Noner   )r   s   "r   r   r    s     ' '& 'r   c                	P    V '       g   R # V P                   V P                  ,          # rB   )r   r  r   s   &r   r   TokenQueue.peek  s    {{4::&&r   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r   r    s     & &4 &r   c                	p    V P                  4       ;p'       g   R # VP                  \        P                  8H  # F)r   r   r  NAMEr.   r   s   & r   r   TokenQueue.peek_name  s)    yy{""xx5::%%r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r    s      # r   c                	    V P                  4       pVP                  \        P                  8w  d   \	        R 4      hVP
                  # )r   )r   r   r  r"  r   r   r#  s   & r   r   TokenQueue.pop_name  s2    hhj88uzz!Z((zzr   c                    V ^8  d   QhRRRR/# )r   r   r3   r   rw   r   )r   s   "r   r   r    s     $ $# $$ $r   c                	T    V P                  4       ;p'       g   R # VP                  V8H  # r!  )r   r   r.   r   r   s   && r   r   TokenQueue.peek_string  s%    yy{""zzV##r   c                    V ^8  d   QhRRRR/# )r   r   r3   r   r   )r   s   "r   r   r    s        r   c                	r    V P                  4       pVP                  V8w  d   \        R 4      hVP                  # )r   )r   r   r   r*  s   && r   r   TokenQueue.pop_string  s.    hhj::\**zzr   c                   V ^8  d   QhRR/# )r   r   r	   r   )r   s   "r   r   r    s      Y r   c                	    V '       g   \        R 4      hV P                  V P                  ,          pV ;P                  ^,          un        V# )r   )r   r   r  r#  s   & r   r   TokenQueue.pop  s4    U##kk$**%

a

r   )r  r  r   N)r   r   r   r   r   r/   r   r   r  r   r   r   r   r   r   r   r   r   r   r   r   u  sF    J#
  -'
&
$
 r   r   )!
__future__r   r+   r   r   r(   r  r   importlib.machineryr   ior   
contextlibr   dataclassesr   	itertoolsr   r	   TYPE_CHECKINGtypingr
   r   r   r   rj   r    r   r5   r8   r   r   r   r   r   r   <module>r:     s    "  	  
   *  % !  77 E76((G, <
p" p"fQ# Q#h	 	 $  
5 5r   