+
     BiI5                    $   ^ RI H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t]'       d   ^ R	IHtHtHtH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)StringIO)contextmanager)	dataclass)chain)	TokenInfoF)AnyIterableIteratorMappingc                   V ^8  d   QhRR/# )   returnModuleCompleter )formats   "0/usr/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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__(   s     5 5": 5d 5r   c                	n    T;'       g    / V n         . V n        \        P                  R ,          V n        R# )NNNN)r   _global_cachesyspath_curr_sys_path)selfr   s   &&r   __init__ModuleCompleter.__init__(   s'    "b79),!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$   r(   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   9   s!     2 2* 2J 29 2r   c                	X   VfE   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$   r3   r5   r"   prefixmodulesmodules   &&&    r   r-   ModuleCompleter.complete9   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"5B'c               $    V ^8  d   QhRRRRRR/# r   r"   r)   r<   r   r6   r   )r   s   "r   r   r   J   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"   r<   r=   mods   &&&  r   r:   ModuleCompleter.find_modulesJ   s7    $$T2  '=w*:*:*<w===s   ;;c               $    V ^8  d   QhRRRRRR/# rA   r   )r   s   "r   r   r   Q   s&     B B# Bs By Br   c                	L   V'       g   \         P                   Uu. uF  pV P                  W24      '       g   K  VNK   	  ppV P                   Uu. uF3  pV P                  VP                  V4      '       g   K'  VP                  NK5  	  pp\        WF,           4      # VP                  R 4      '       d4   V P                  P                  RR4      pV P                  W4      pVf   . # V P                  pVP                  R 4       FL  p	V U
u. uF,  p
V
P                  '       g   K  V
P                  V	8X  g   K*  V
NK.  	  pp
V P                  V4      pKN  	  V Uu. uF3  pV P                  VP                  V4      '       g   K'  VP                  NK5  	  up# u upi u upi u up
i u upi ).r    )r!   builtin_module_namesis_suggestion_matchglobal_cacher5   sorted
startswithr   getresolve_relative_namesplitispkgiter_submodules)r$   r"   r<   r5   builtin_modulesr>   third_party_modulespackager=   segmentmod_infos   &&&        r   rC   ModuleCompleter._find_modulesQ   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zz#G07 GH"..  -5]]g-E  xG G**73G ' +2 B'++FKK@ ' B 	B%J#UGBs4   FF$F8F	F"F5F$F!?F!c               $    V ^8  d   QhRRRRRR/# )r   module_namer)   r<   r   boolr   )r   s   "r   r   r   i   s!     / /s /C /D /r   c                	`    V'       d   VP                  V4      # VP                  R 4      '       * # )_)rO   )r$   r\   r<   s   &&&r   rL   #ModuleCompleter.is_suggestion_matchi   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   p   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).0specs   & r   	<genexpr>2ModuleCompleter.iter_submodules.<locals>.<genexpr>t   s(      3
 <GD6;;s   	%%)	rS   module_finder	find_specr5   setr   from_iterablepkgutiliter_modules)r$   rb   infospecssearch_locationss   &&   r   rT   ModuleCompleter.iter_submodulesp   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_namer)   r   ztuple[str, str]r   )r   s   "r   r   r   z   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'
rI   rJ   )rO   lstriplenrsplit)r$   rw   strippeddotsr"   r<   s   &&    r   r9   #ModuleCompleter.get_path_and_prefixz   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"   r)   r>   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# )rJ   rI   )endswith)r$   r"   r>   s   &&&r   r;   !ModuleCompleter.format_completion   s7    2:s++VF8$$q!!r   c               $    V ^8  d   QhRRRRRR/# )r   r5   r)   rW   r   r4   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'
rI   N)r{   rz   )r$   r5   rW   level	characterbitsbases   &&&    r   rQ   %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   rc   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"   listrp   rq   r$   s   &r   rM   ModuleCompleter.global_cache   sS     !!!T%8%8CHH%D"%((1+D!%g&:&:&<!=D!!!r   )r#   r    r   r8   )__name__
__module____qualname____firstlineno____doc__r%   r0   r-   r:   rC   rL   rT   r9   r;   rQ   propertyrM   __static_attributes__r   r   r   r   r      sN    5

2">B0/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# )r+   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   coder)   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
TokenErrorr)   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# r8   )_parser3   r5   )r$   ress   & r   r,   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r8   )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 rJ   )r5   ,r   rI   )r   rstripr   r   r   peek_string
ParseErrorparse_dotted_namerO   popparse_dotted_as_name)r$   r5   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   rJ   )r3   r5   from)r3   (r   r   rI   )
r   r   r   r   parse_empty_from_importr   r   r   r   
pop_string)r$   r|   r5   r3   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   r)   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     s      C r   c                	\    V P                  4       pV P                  P                  R 4       V# )r   )r   r   r   )r$   r3   s   & r   r   ImportParser.parse_from  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     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      # )rI   r   rJ   Nr   )r   r   r   r   	peek_namepeekstring	_keywordsr   r   join)r$   r5   toks   &  r   r   ImportParser.parse_dotted_name  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   8  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_names8  sB    kk%%c**KKOO  +r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r   >  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_name>  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%   r,   r   r   r   r   r   r   r   r   r   r   r   r   r   r+   r+      sy      	ellEMM%--O )I/$'
')$6&!
,#4!# #r   r+   c                      ] tR tRtRtR# )r   iE  r   N)r   r   r   r   r   r   r   r   r   r   E  s    r   r   T)frozenc                  4    ] tR tRt$ RtR]R&   RtR]R&   RtR# )r   iI  Nr4   r3   r5   r   )r   r   r   r   r3   __annotations__r5   r   r   r   r   r   r   I  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   iO  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__R  s     # # #4 #r   c                	.    Wn         ^ V n        . V n        R# )r   N)r   indexstack)r$   r   s   &&r   r%   TokenQueue.__init__R  s    '-
 "
r   c                   V ^8  d   QhRR/# )r   r   r	   r   )r   s   "r   r   r   X  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r8   )r   r   r   r   r   r   s   &r   r   TokenQueue.save_stateW  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   r]   r   )r   s   "r   r   r   a  s     - -$ -r   c                	F    V P                   \        V P                  4      8  # r8   )r   rz   r   r   s   &r   __bool__TokenQueue.__bool__a  s    zzC,,,r   c                   V ^8  d   QhRR/# )r   r   zTokenInfo | Noner   )r   s   "r   r   r   d  s     ' '& 'r   c                	P    V '       g   R # V P                   V P                  ,          # r8   )r   r   r   s   &r   r   TokenQueue.peekd  s    {{4::&&r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r   i  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_namei  s)    yy{""xx5::%%r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r   n  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_namen  s2    hhj88uzz!Z((zzr   c                    V ^8  d   QhRRRR/# )r   r   r)   r   r]   r   )r   s   "r   r   r   t  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_stringt  s%    yy{""zzV##r   c                    V ^8  d   QhRRRR/# )r   r   r)   r   r   )r   s   "r   r   r   y  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_stringy  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   O  sF    J#
  -'
&
$
 r   r   )
__future__r   rp   r!   r   r   ior   
contextlibr   dataclassesr   	itertoolsr   r   TYPE_CHECKINGtypingr	   r
   r   r   r   r   r+   r.   r   r   r   r   r   r   <module>r      s    "  
    % !  77<
V" V"rQ# Q#h	 	 $  
5 5r   