
    ^hk%                         S SK r S SKJr  S SKJrJrJr  S SKJr  S SK	J
r
  S SKJr  SR                  5       r " S S	5      r " S
 S5      rS rS rS rS rS\S\S\4S jrg)    NPath)DictIterableTuple)split_lines)RefactoringError)ImplicitNSNamezmor_test and_test not_test comparison expr xor_expr and_expr shift_expr arith_expr term factor power atom_exprc                   2    \ rS rSrS rS rS rS rS rSr	g)	ChangedFile   c                 @    Xl         X l        X0l        X@l        XPl        g N)_inference_state
_from_path_to_path_module_node_node_to_str_map)selfinference_state	from_pathto_pathmodule_nodenode_to_str_maps         W/home/james-whalen/.local/lib/python3.13/site-packages/jedi/api/refactoring/__init__.py__init__ChangedFile.__init__   s     /#' /    c                    [        U R                  R                  5       SS9n[        U R                  5       SS9nUS   S:w  a  US==   S-  ss'   US   S:w  a  US==   S-  ss'   U R                  R
                  R                  nU R                  c  SnO U R                  R                  U5      nU R                  c  SnO U R                  R                  U5      n[        R                  " X[        U5      [        U5      S9nSR                  U5      R                  S5      $ ! [         a    U R                  n Nf = f! [         a    U R                  n N|f = f)NTkeepends 
)fromfiletofile )r   r   get_codeget_new_coder   projectpathr   relative_to
ValueErrorr   difflibunified_diffstrjoinrstrip)r   	old_lines	new_linesproject_pathfrom_pto_pdiffs          r   get_diffChangedFile.get_diff   sB    1 1 : : <tL	 1 1 3dC	 R=BbMT!MR=BbMT!M,,4499??"F)44\B == D%}}00> ##[t9
 wwt}##C((!  ))  %}}%s$   D' E 'E ?E EEc                 v    U R                   R                  R                  U R                  U R                  5      $ r   )r   grammarrefactorr   r   r   s    r   r)   ChangedFile.get_new_codeB   s-    $$,,55d6G6GI^I^__r   c                     U R                   c  [        S5      e[        U R                   SSS9 nUR                  U R	                  5       5        S S S 5        g ! , (       d  f       g = f)Nz5Cannot apply a refactoring on a Script with path=Nonewr#   )newline)r   r	   openwriter)   )r   fs     r   applyChangedFile.applyE   sQ    ??""G  $//33qGGD%%'( 433s    A
A%c                 T    SU R                   R                  < SU R                  < S3$ )N<z: >)	__class____name__r   r>   s    r   __repr__ChangedFile.__repr__N   s    !^^44dooFFr   )r   r   r   r   r   N)
rL   
__module____qualname____firstlineno__r   r9   r)   rF   rM   __static_attributes__ r   r   r   r      s    0')R`)Gr   r   c                   `    \ rS rSrS
S jrS\\\4   4S jrS\	\
\\4      4S jrS rS rSrg	)RefactoringR   c                 (    Xl         X0l        X l        g r   )r   _renames_file_to_node_changes)r   r   file_to_node_changesrenamess       r   r   Refactoring.__init__S   s     /%9"r   returnc                 $  ^ U4S jnU R                  5       m[        U R                  R                  5       S S9 VVs0 s HC  u  p#U[	        U R
                  UU" U5      [        [        U5      5      R                  5       US9_ME     snn$ s  snnf )Nc                    > U c  U $ [        U 5      n T HI  u  pU R                  [        U5      5      (       d  M&  [        U5      U [        [        U5      5      S  -   n MK     [        U 5      $ r   )r0   
startswithlenr   )pfrom_tor[   s      r   calculate_to_path8Refactoring.get_changed_files.<locals>.calculate_to_pathY   s^    yAA$	<<E
++B!CE
O$4"55A % 7Nr   c                 0    U S   =(       d    [        S5      $ )Nr   r#   r   )xs    r   <lambda>/Refactoring.get_changed_files.<locals>.<lambda>n   s    ad.d2h.r   )key)r   r   r   r   )	get_renamessortedrY   itemsr   r   nextiterget_root_node)r   re   r+   map_r[   s       @r   get_changed_filesRefactoring.get_changed_filesX   s    	 ""$ %**002.

 +%%)$/ d,::< $ 
 	
 
s   A
Bc                 ,    [        U R                  5      $ )z(
Files can be renamed in a refactoring.
)rm   rX   r>   s    r   rl   Refactoring.get_renamesr   s     dmm$$r   c           	      &   SnU R                   R                  R                  nU R                  5        H%  u  p4US[	        X25      < S[	        XB5      < S3-  nM'     USR                  S U R                  5       R                  5        5       5      -   $ )Nr#   zrename from z
rename to r$   c              3   @   #    U  H  oR                  5       v   M     g 7fr   )r9   ).0rE   s     r   	<genexpr>'Refactoring.get_diff.<locals>.<genexpr>   s     V4Uqjjll4Us   )r   r*   r+   rl   _try_relative_tor1   rs   values)r   textr5   rc   rd   s        r   r9   Refactoring.get_diffx   s    ,,4499))+IE#E8:J2:\^ ^D , bggVD4J4J4L4S4S4UVVVVr   c                     U R                  5       R                  5        H  nUR                  5         M     U R                  5        H  u  p#UR	                  U5        M     g)zE
Applies the whole refactoring to the files, which includes renames.
N)rs   r}   rF   rl   rename)r   rE   oldnews       r   rF   Refactoring.apply   sK     '')002AGGI 3 ((*HCJJsO +r   )rY   r   rX   N)rS   )rL   rO   rP   rQ   r   r   r   r   rs   r   r   rl   r9   rF   rR   rS   r   r   rU   rU   R   sB    :

4k(9#: 
4%XeD$J&78 %Wr   rU   c                     U R                   nU R                  S;   a  X"R                   R                  U5      4$ XR                  XR                  -   5      4$ )N)z__init__.pyz__init__.pyi)parentnamejoinpathsuffix)r+   new_namedir_s      r   _calculate_renamer      sI    ;;Dyy33[[))(333x++5666r   c           	      ~   [        5       n0 nU(       d  [        S5      eU GH  nUR                  R                  nUR                  S:X  aA  Uc>  UR
                  b1  [        UR
                  5      nUR                  [        Xr5      5        Mk  [        UR                  [        5      (       aQ  UR                  R                  R                  5        H'  nUR                  [        [        U5      U5      5        M)     M  Uc  M  UR                  UR
                  0 5      nUR                  U-   X'   GM     [        XU5      $ )N!There is no name under the cursormodule)setr	   _name	tree_nametypemodule_pathr   addr   
isinstancer
   _value
py__path__
setdefaultprefixrU   )	r   definitionsr   file_renamesfile_tree_name_mapdr   rb   fmaps	            r   r   r      s    5LBCC GG%%	66X)"38QQ]]#A.q;<00WW^^..0  !247H!EF 1 $)44Q]]BG"+"2"2X"=  LIIr   c                    U(       d  [        S5      e[        S U 5       5      (       a  [        S5      e[        S U 5       5      (       a  [        S5      eU Vs/ s H%  o"R                  R                  5       (       d  M#  UPM'     nn[	        U5      S:X  a  [        S5      e[	        U5      S:  a  [        S	5      e[	        U5      S:X  a  [        S
5      eUS   R                  nUR                  5       nUR                  S:w  a<  [        SSS9R                  UR                  UR                  5      n[        SU-  5      e[	        UR                  SS95      S:  a  [        S5      eUR                  S   nUR                  S:X  a(  [	        UR                  5      S:X  a  UR                  S   nUS:w  a6  UR                  S:X  a  [        S5      e[        SUR                  SS9-  5      eUR                  5       nUR                  SS9n	U Vs/ s H%  o"R                  R                  5       (       a  M#  UPM'     n
n0 nU
 GH^  nUR                  nUR                  5       R                  5       nU	nUR                  S:X  dS  UR                  R                  [         ;   d5  UR                  R                  S:X  a#  UR                  R#                  5       b  SU	-   S-   nUR%                  U0 5      nUnUR&                  nUR                  nUR                  S:X  a  UR                  S   S:X  am  UR                  R                  S   R&                  nUnUR                  R                  S UR                  R                  R)                  U5        H  nS UU'   M
     UU-   X'   GMa     US   R                  5       R                  5       nUR%                  U0 5      n[+        UR-                  5       R&                  5      UU'   UR/                  5       nUR&                  R1                  S!5      S :X  a  UR                  S":X  d  US#:X  a  S UU'   [3        X5      $ s  snf s  snf )$Nr   c              3   >   #    U  H  oR                   S ;   v   M     g7f))r   	namespaceN)api_typery   ns     r   rz   inline.<locals>.<genexpr>   s     
@%Q::00%s   z,Cannot inline imports, modules or namespacesc              3   <   #    U  H  oR                   S L v   M     g 7fr   )r   r   s     r   rz   r      s     
.1;;$s   z!Cannot inline builtins/extensionsr   zNo definition found to inline   z.Cannot inline a name with multiple definitionsz$There are no references to this name	expr_stmtfunctionclass)funcdefclassdefzCannot inline a %sT)include_setitemz3Cannot inline a statement with multiple definitions	annassign      =z:Cannot inline a statement that is defined by an annotationz#Cannot inline a statement with "%s"F)include_prefixtestlist_star_exprtrailer().r#   z 	rB   ;)r	   anyr   is_definitionra   get_definitionr   dictgetget_defined_nameschildrenr(   get_rhsget_root_context
py__file__r   EXPRESSION_PARTSget_next_siblingr   r   index_remove_indent_of_prefixget_first_leafget_next_leafstriprU   )r   namesr   r   r   r   type_first_childrhsreplace_code
referencesrZ   r   r+   sof_pathr   par	some_nodechanges	next_leafs                        r   inliner      s   BCC

@%
@@@MNN

.
...BCC#Ce{{'@'@'B1eKC
;1>??
;!OPP
5zQEFFA((I((*I~~$
 #inninn
- 	 3e;<<
9&&t&<=ATUU$$Q'K;&3{/C/C+D+I!**1-c{*"L  #5&&e&<= 
 


C<<u<5L"FU++*C*C*E!UJFNN	$$&11388++##((,<<##((I5$$557Cl"S(A&11$;hh88y S\\!_%;ZZ((+22FA ZZ001P#**2E2E2K2KC2PQ	%'	" RaZ
) , q>**,779D"--dB7G1)2J2J2L2S2STGI'')I e$*9,	S0@	==O DJ Gs   "QQ"Q5Qc                 :    SR                  [        U SS9SS 5      $ )zL
Removes the last indentation of a prefix, e.g. " \n \n " becomes " \n \n".
r#   Tr    Nr"   )r1   r   )r   s    r   r   r      s!     77;v5cr:;;r   r+   baser]   c                 J     U R                  U5      $ ! [         a    U s $ f = fr   )r,   r-   )r+   r   s     r   r|   r|     s,    %% s    "")r.   pathlibr   typingr   r   r   parsor   jedi.api.exceptionsr	   jedi.inference.value.namespacer
   splitr   r   rU   r   r   r   r   r|   rS   r   r   <module>r      su      ( (  0 9O%' ?G ?GD7 7t7J0O>d<4 t  r   