+
    ^|ie                       ^ RI Ht ^ RIt^ RIt^ RIt^ RI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HtHtHt ^ RIHtHt ^ RIHt ]'       db   ]P0                  ]P2                  ,          ]P4                  ,          ]P6                  ,          ]P8                  ,          ]P:                  ,          tR R ltR	 R
 lt  ! R R]4      t! ! R R]4      t" ! R R]PF                  4      t$ ! R R4      t% ! R R]4      t&R# )    )annotationsN)
ModuleType)TYPE_CHECKINGAny
NamedTuplecast)	GeneratorIterable)DeduperReloaderPatchingMixinc                    V ^8  d   QhRRRR/# )   modulezModuleType | strreturnz
str | None )formats   "P/usr/lib/python3/dist-packages/IPython/extensions/deduperreload/deduperreload.py__annotate__r      s     . .!1 .j .    c                    \        V \        4      '       d    \        P                  P	                  V 4      MT ;pf   R# \        VRR4      ;'       g    R# )zHReturns the module's file path, or the empty string if it's inaccessible __file__)
isinstancestrsysmodulesgetgetattr)r   mods   & r   get_module_file_namer      sB    *4VS*A*As{{v&vMV3
B'--2-r   c               $    V ^8  d   QhRRRRRR/# )r   node1zast.AST | list[ast.AST]node2r   boolr   )r   s   "r   r   r   &   s$      . 7N SW r   c                Z   \        V 4      \        V4      Jd   R# \        V \        P                  4      '       d^   V P                  P                  4        F=  w  r#VR9   d   K  \        W4      '       d   \        V\        W4      4      '       d   K<   R# 	  R# \        V \        4      '       d|   \        V\        4      '       df   \        V 4      \        V4      8H  ;'       dG    \        ;QJ d%    R \        W4       4       F  '       d   K   R# 	  R# ! R \        W4       4       4      # W8H  # )zYChecks if node1 and node2 have identical AST structure/values, apart from some attributesFTc              3  <   "   T F  w  r\        W4      x  K  	  R # 5iN)compare_ast).0n1n2s   &  r   	<genexpr>compare_ast.<locals>.<genexpr>=   s      0
.?FBK.?s   )lineno
end_lineno
col_offsetend_col_offsetctxparent)typer   astAST__dict__itemshasattrr'   r   listlenallzip)r!   r"   kvs   &&  r   r'   r'   &   s    E{$u+%%!!NN((*DA   5$$K75;L,M,M + 	E4	 	 Zt& & 5zSZ' 
 
CC 0
.1%.?0
CC 	
C 	
C 0
.1%.?0
 -
 	
 ~r   c                  0    ] tR t^Dt$ RtR]R&   R]R&   RtR# )DependencyNodea  
Each node represents a function.
qualified_name: string which represents the namespace/name of the function
abstract_syntax_tree: subtree of the overall module which corresponds to this function

qualified_name is of the structure: (namespace1, namespace2, ..., name)

For example, foo() in the following would be represented as (A, B, foo):

class A:
    class B:
        def foo():
            pass
tuple[str, ...]qualified_nameast.ASTabstract_syntax_treer   N)__name__
__module____qualname____firstlineno____doc____annotations____static_attributes__r   r   r   r@   r@   D   s     $#!!r   r@   c                      ] tR t^Xt$ . tR]R&   . tR]R&   . tR]R&   / tR]R&   . t	R	]R
&   ]
R R l4       tR R ltR R ltRtR# )GatherResultz9list[tuple[tuple[str, ...], ast.Import | ast.ImportFrom]]import_defsz8list[tuple[tuple[str, ...], ast.Assign | ast.AnnAssign]]assign_defszDlist[tuple[tuple[str, ...], ast.FunctionDef | ast.AsyncFunctionDef]]function_defszdict[str, ast.ClassDef]classeszlist[ast.AST]	unfixablec                   V ^8  d   QhRR/# )r   r   rM   r   )r   s   "r   r   GatherResult.__annotate__b   s     ' '| 'r   c                	    V ! . . . / . 4      # r&   r   )clss   &r   createGatherResult.createa   s    2r2r2&&r   c                   V ^8  d   QhRR/# )r   r   z0Iterable[tuple[tuple[str, ...], TDefinitionAst]]r   )r   s   "r   r   rT   e   s     W WJ Wr   c                	n    \         P                  ! V P                  V P                  V P                  4      # r&   )	itertoolschainrN   rO   rP   selfs   &r   all_defsGatherResult.all_defse   s'    t//1A1A4CUCUVVr   c                    V ^8  d   QhRRRR/# )r   otherrM   r   Noner   )r   s   "r   r   rT   h   s     / /< /D /r   c                	x   V P                   P                  VP                   4       V P                  P                  VP                  4       V P                  P                  VP                  4       V P                  P                  VP                  4       V P                  P                  VP                  4       R # r&   )rN   extendrO   rP   rQ   updaterR   )r^   rb   s   &&r   inplace_mergeGatherResult.inplace_mergeh   s|     1 12 1 12!!%"5"56EMM*eoo.r   r   N)rE   rF   rG   rH   rN   rJ   rO   rP   rQ   rR   classmethodrW   r_   rg   rK   r   r   r   rM   rM   X   se    MOKJOLNKIN 	    (*G$)!I}!' 'W/ /r   rM   c                     a  ] tR t^ptR R lt]P                  R R l4       tR R ltR R lt	R	 V 3R
 llt
R R ltRtV ;t# )ConstexprDetectorc                   V ^8  d   QhRR/# r   r   rc   r   )r   s   "r   r   ConstexprDetector.__annotate__q   s     / /$ /r   c                	"    R V n         R V n        R# TN)is_constexpr_allow_builtins_exceptionsr]   s   &r   __init__ConstexprDetector.__init__q   s     *.'r   c                   V ^8  d   QhRR/# )r   r   zGenerator[None, None, None]r   )r   s   "r   r   rn   v   s     9 9.I 9r   c              #  	`   "   V P                   pR V n          Rx  Wn         R#   Yn         i ; i5i)FN)rr   )r^   
prev_allows   & r   disallow_builtins_exceptions.ConstexprDetector.disallow_builtins_exceptionsu   s,     44
*/'	9.8+j+s   .# .+.c                    V ^8  d   QhRRRR/# )r   nodezast.Attributer   rc   r   )r   s   "r   r   rn   ~   s     # #M #d #r   c                	    V P                  4       ;_uu_ 4        V P                  VP                  4       R R R 4       R #   + '       g   i     R # ; ir&   )rx   visitvaluer^   r{   s   &&r   visit_Attribute!ConstexprDetector.visit_Attribute~   s0    ..00JJtzz" 1000s	   ?A	c                    V ^8  d   QhRRRR/# )r   r{   zast.Namer   rc   r   )r   s   "r   r   rn      s     " "x "D "r   c                	|    V P                   '       d#   \        \        VP                  4      '       d   R # RV n        R # NF)rr   r8   builtinsidrq   r   s   &&r   
visit_NameConstexprDetector.visit_Name   s)    ***wx/I/I!r   c                    V ^8  d   QhRRRR/# )r   r{   rC   r   rc   r   )r   s   "r   r   rn      s      ' d r   c                	N   < V P                   '       g   R # \        SV `	  V4       R # r&   )rq   superr}   )r^   r{   	__class__s   &&r   r}   ConstexprDetector.visit   s       dr   c                    V ^8  d   QhRRRR/# )r   r{   rC   r   r#   r   )r   s   "r   r   rn      s     ! !W ! !r   c                	J    R V n         V P                  V4       V P                   # T)rq   r}   r   s   &&r   __call__ConstexprDetector.__call__   s"     

4   r   )rr   rq   )rE   rF   rG   rH   rs   
contextlibcontextmanagerrx   r   r   r}   r   rK   __classcell__)r   s   @r   rk   rk   p   s@    / 9 9#"
 ! !r   rk   c                  2    ] tR t^tRtR R ltR R ltRtR# )AutoreloadTreeas  
Recursive data structure to keep track of reloadable functions/methods. Each object corresponds to a specific scope level.
children: classes inside given scope, maps class name to autoreload tree for that class's scope
funcs_to_autoreload: list of function names that can be autoreloaded in given scope.
new_nested_classes: Classes getting added in new autoreload cycle
c                   V ^8  d   QhRR/# rm   r   )r   s   "r   r   AutoreloadTree.__annotate__   s     9 9$ 9r   c                	N    / V n         . V n        \        4       V n        / V n        R # r&   )childrendefs_to_reloadsetdefs_to_deletenew_nested_classesr]   s   &r   rs   AutoreloadTree.__init__   s#    35EG(+68r   c                    V ^8  d   QhRRRR/# )r   prefixesz	list[str]r   r   r   )r   s   "r   r   r      s     	 	) 	 	r   c                    T pV F=  pW2P                   9  d   \        4       VP                   V&   VP                   V,          pK?  	  V# )zI
Return ref to the AutoreloadTree at the namespace specified by prefixes
)r   r   )r^   r   curprefixs   &&  r   traverse_prefixes AutoreloadTree.traverse_prefixes   sC     F\\)'5'7V$,,v&C  
r   )r   r   r   r   N)rE   rF   rG   rH   rI   rs   r   rK   r   r   r   r   r      s    9	 	r   r   c                  Z   ] tR t^tRtR R lt]R R l4       t]P                  R R l4       tR R	 lt	]
! 4       t]R
 R l4       t]R R l4       t]R R l4       tR(R R lltR R ltR R ltR(R R lltR R ltR(R R lltR(R R lltR R  ltR! R" ltR(R# R$ lltR% R& ltR'tR# ))DeduperReloadera  
This version of autoreload detects when we can leverage targeted recompilation of a subset of a module and patching
existing function/method objects to reflect these changes.

Detects what functions/methods can be reloaded by recursively comparing the old/new AST of module-level classes,
module-level classes' methods, recursing through nested classes' methods. If other changes are made, original
autoreload algorithm is called directly.
c                   V ^8  d   QhRR/# rm   r   )r   s   "r   r   DeduperReloader.__annotate__   s      $ r   c                	N    \        4       V n        / V n        / V n        R V n        R# rp   )r   _to_autoreloadsource_by_modnamedependency_graph_enabledr]   s   &r   rs   DeduperReloader.__init__   s$    .<.>13MOr   c                   V ^8  d   QhRR/# r   r   r#   r   )r   s   "r   r   r      s     O O Or   c                	Z    V P                   ;'       d    \        P                  ! 4       R 8H  # )CPython)r   platformpython_implementationr]   s   &r   enabledDeduperReloader.enabled   s"    }}NN!?!?!AY!NNr   c                    V ^8  d   QhRRRR/# )r   r~   r#   r   rc   r   )r   s   "r   r   r      s      T d r   c                	    Wn         R # r&   )r   )r^   r~   s   &&r   r   r      s    r   c                   V ^8  d   QhRR/# rm   r   )r   s   "r   r   r      s     9 9 9r   c                `   V P                   '       g   R# \        P                  P                  4       V P                  P                  4       ,
           F  p\        P                  V,          p\        V4      ;pe:   RV9   g3   RV9   g,   \        P                  ! V\        P                  4      '       g   RV P                  V&   Ks  VP                  R4      '       g   RV P                  V&   K   \        VRRR7      ;_uu_ 4       pVP                  4       V P                  V&   RRR4       K  	  R#   + '       g   i     K  ; i  \         d_   p\        P                  ! R	4      pTP                  R
T RT R\!        T4      P"                   24       RT P                  T&    Rp?EKV  Rp?ii ; i)zI
Update dictionary source_by_modname with current modules' source codes.
Nzsite-packageszdist-packagesr   z.pyrutf8encoding
autoreloadFailed to read module file '' for module '': )r   r   r   keysr   r   osaccessR_OKendswithopenread	Exceptionlogging	getLogger	exceptionr3   rE   )r^   new_modname
new_modulefnamefeloggers   &      r   update_sourcesDeduperReloader.update_sources   s^    |||;;++-0F0F0K0K0MMMK[1J.z::C"e+"e+yy0068&&{3>>%((68&&{39%v66!:;&&(D**;7 76 N 766 9 **<8  25'}TWX\]^X_XhXhWij 79&&{339s7   .ED0"E0E;EEF-AF((F-c                    V ^8  d   QhRRRR/# )r   r{   ast.Module | ast.ClassDefr   r#   r   )r   s   "r   r   r      s      8 T r   c                	   \        V \        P                  4      '       d   R # V P                   F  p\        V\        P                  4      '       d   VP
                  R8X  d    R# \        V\        P                  4      '       g   KY  VP                  R8X  g   Kl  \        VP                  \        P                  4      '       g   K  VP                  P
                  R8X  g   K   R# 	  R # )FEnumTenum)	r   r4   ModulebasesNamer   	Attributeattrr~   )r{   bases   & r   is_enum_subclass DeduperReloader.is_enum_subclass   s    dCJJ''JJD$))dgg.?4//II'tzz38844JJMMV+  r   c               $    V ^8  d   QhRRRRRR/# )r   r{   rC   parent_noder   r   r#   r   )r   s   "r   r   r      s$     
2 
2
2)B
2	
2r   c                	   \        V\        P                  \        P                  34      '       d   VP                  f   R# V P                  V4      '       d   R# \        V\        P                  4      '       d   VP                  MVP                  . F&  p\        V\        P                  4      '       d   K%   R# 	  V P                  VP                  4      # r   )
r   r4   Assign	AnnAssignr~   r   targetstargetr   constexpr_detector)rV   r{   r   r   s   &&& r   is_constexpr_assign#DeduperReloader.is_constexpr_assign   s     $S]] ;<<

@R,,&0szz&B&BdllUFfchh// V %%djj11r   c               $    V ^8  d   QhRRRRRR/# )r   bodylist[ast.stmt]r   r   r   rM   r   )r   s   "r   r   r     s$     9 9!90I9	9r   c                	   \         P                  4       pV EF  pTp\        V\        P                  4      '       d   VP
                  pK.  \        V\        P                  \        P                  34      '       d+   VP                  P                  VP                  3V34       K  \        V\        P                  \        P                  34      '       d_   VP                  P                  \        ;QJ d    . R VP                   4       F  NK  	  5M! R VP                   4       4      V34       EK  \        V\        P                   4      '       d   WSP"                  VP                  &   EKW  \        V\        P$                  4      '       d   VP&                  P                  VP(                  4       VP+                  V P-                  VP.                  V4      4       VP+                  V P-                  VP0                  V4      4       EK  \        V\        P2                  \        P4                  34      '       dT   VP&                  P7                  VP8                  4       VP+                  V P-                  VP.                  V4      4       EKx  \        V\        P:                  4      '       d   VP+                  V P-                  VP.                  V4      4       VP+                  V P-                  VP0                  V4      4       VP+                  V P-                  VP<                  V4      4       VP>                   Fa  pVP@                  e&   VP&                  P                  VP@                  4       VP+                  V P-                  VP.                  V4      4       Kc  	  EK  \        V\        PB                  \        PD                  34      '       d   EK  V PG                  WR4      '       d   \        V\        PH                  \        PJ                  34      '       g   Q h\        V\        PH                  4      '       d   VPL                  MVPN                  .pVPP                  P                  \        ;QJ d    . R V 4       F  NK  	  5M! R V 4       4      V34       EK  VP&                  P                  V4       EK  	  V# )z
Given list of ast elements, return:
1. dict mapping function names to their ASTs.
2. dict mapping class names to their ASTs.
3. list of any other ASTs.
c              3  `   "   T F$  qP                   ;'       g    VP                  x  K&  	  R # 5ir&   )asnamename)r(   r   s   & r   r+   3DeduperReloader._gather_children.<locals>.<genexpr>  s!     N;;33$))3s   ..c              3  j   "   T F)  p\        \        P                  V4      P                  x  K+  	  R # 5ir&   )r   r4   r   r   )r(   r   s   & r   r+   r   6  s!     !R'$sxx"8";";'s   13))rM   rW   r   r4   Exprr~   FunctionDefAsyncFunctionDefrP   appendr   Import
ImportFromrN   tuplenamesClassDefrQ   IfrR   testrg   _gather_childrenr   orelse	AsyncWithWithre   r7   Try	finalbodyhandlersr3   ConstantPassr   r   r   r   r   rO   )rV   r   r   resultast_nodeast_elthandlerr   s   &&&     r   r   DeduperReloader._gather_children  sC    $$&H+3GWchh//!--'COOS5I5I#JKK$$++gll_g,FGGcjj#..%ABB""))UNNUUNNNPWX GS\\22/6w||,GSVV,,  ''5$$S%9%9',,%TU$$S%9%9'..+%VWGcmmSXX%>??  ''6$$S%9%9',,%TUGSWW--$$S%9%9',,%TU$$S%9%9'..+%VW$$(():):KH  '//G||/((//=((,,W\\;G  0  #,,)ABB**7@@%g

CMM/JKKKK &gszz::  %nn- 
 &&--!E!R'!REE!R'!RR# $$++G4] ^ r   Nc               (    V ^8  d   QhRRRRRRRR/# )r   old_noder   new_noder   list[str] | Noner   r#   r   )r   s   "r   r   r   >  s2     4 4+4 ,4 #	4
 
4r   c                   V P                   '       g   R# T;'       g    . pV P                  VP                  V4      pV P                  VP                  V4      pVP                  4        UUUu/ uF  w  rgV F  qVbK  	  K  	  p	pppVP                  4        UUUu/ uF  w  rgV F  qVbK  	  K  	  p
ppp\	        VP
                  VP
                  4      '       g   R# V P                  P                  V4      pVP                  4        F  w  rl. pV FB  pW,          VJd   K  W9  g   \	        WV,          4      '       d   K1  VP                  V4       KD  	  V'       g   KY  VP                  P                  \        V4      V34       K  	  V;P                  \        V	P                  4       4      \        V
P                  4       4      ,
          ,          un        VP                  P                  4        F}  w  rWP                  9  d   WP                   V&   K%  \	        WP                  V,          4      '       d   KI  V P#                  VP                  V,          WV.,           4      '       d   K|   R# 	  R# u upppi u upppi )z
Returns
-------
`True` if we can run our targeted autoreload algorithm safely.
`False` if we should instead use IPython's original autoreload implementation.
FT)r   r  r   r_   r'   rR   r   r   r   r   r   r   r   r   rQ   r7   r   detect_autoreload)r^   r  r  r   
old_result
new_resultr   ast_defr   old_defs_by_namenew_defs_by_namer   new_ast_defnames_to_reloadnew_ast_def_classs   &&&&           r   r  !DeduperReloader.detect_autoreload>  s6    |||>>r**8==(C
**8==(C
0:0C0C0E0
0EneRW$'MRWD0E 	 0
 1;0C0C0E0
0EneRW$'MRWD0E 	 0
 ://1E1EFF!!33H=","5"5"7E O#)</{$!78 8 $**40  ""))5<*EF #8 	c"2"7"7"9:S!!#>
 
 	
 (2'9'9'?'?'A#D---/@&&t, !#5#5d#; ,,""4(*;=N   (B E0
0
s   -I6I=c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r   t  s      4 r   c                V    V P                  4        F  pV P                  V4       K  	  R# )z
If a decorator function is modified, we should similarly reload the functions which are decorated by this
decorator. Iterate through the Dependency Graph to find such cases in the given AutoreloadTree.
T)_check_dependents_inner_add_node_to_autoreload_treer   s   & r   _check_dependents!DeduperReloader._check_dependentst  s(    
 002D--d3 3r   c                    V ^8  d   QhRRRR/# )r   r{   r@   r   rc   r   )r   s   "r   r   r   }  s     
 
 
D 
r   c                2   \        VP                  4      ^ 8X  d   R# V P                  P                  \	        VP                  RR 4      4      pVP
                  e<   VP                  P                  VP                  R,          3VP
                  34       R# R# )zZ
Given a node of the dependency graph, add decorator dependencies to the autoreload tree.
N)r:   rB   r   r   r9   rD   r   r   )r^   r{   r   s   && r   r$  ,DeduperReloader._add_node_to_autoreload_tree}  s     t""#q(!!33D9L9LSb9Q4RS$$0%%%%b)+T-F-FG 1r   c                    V ^8  d   QhRRRR/# )r   r   r  r   list[DependencyNode]r   )r   s   "r   r   r     s      (	r   c                	`   T;'       g    . pV P                   P                  V4      p. pVP                   F:  w  vp p\        W.,           4      pVP	                  V P                  V4      4       K<  	  VP                   F*  pVP	                  V P                  W.,           4      4       K,  	  V# r&   )r   r   r   r   re   _gen_dependentsr   r#  )r^   r   r   ans	func_name_r{   
class_names   &&      r   r#  'DeduperReloader._check_dependents_inner  s     >>r!!33H="%"4"4OYQK/0DJJt++D12 #5 00JJJt33H|4KLM 1
r   c                    V ^8  d   QhRRRR/# )r   qualnamerA   r   r,  r   )r   s   "r   r   r     s       <P r   c                	    . pWP                   9  d   . # V P                   V,           F>  pVP                  V P                  VP                  4      4       VP	                  V4       K@  	  V# r&   )r   re   r.  rB   r   )r^   r5  r/  elts   &&  r   r.  DeduperReloader._gen_dependents  s_    000I((22CJJt++C,>,>?@JJsO 3 
r   c               $    V ^8  d   QhRRRRRR/# r   nszModuleType | typer   r  r   r#   r   )r   s   "r   r   r     s)     r r#r/?r	rr   c           
        T;'       g    . pV P                   P                  V4      pTpV F  pVP                  V,          pK  	  \        4       pVP                   EF
  w  rx\        V4      ^8X  d   V^ ,          V9   d   K&  VP                  V4       / p	\        V\        P                  \        P                  34      '       EdJ   V^ ,          ;qP                  9   Ed0   \        V4      ^8X  g   Q hVP                  V
,          p\        V\        \        34      '       d   VP                  p\        P                  ! \        P                   ! V4      4      p\        V4      ^ 8  ;p'       d   R\        P"                  ! VR4      ,           pVP                  p\        V\$        4      '       g   \%        V4      p\'        VRR4      ;'       d    VP(                  P*                  ;'       g    Rp\        P,                  ! V4      .p\        \/        \        P                  V^ ,          P0                  ^ ,          4      P2                  4      ^ 8  dt   \4        P6                  ! \4        P8                  ! V^ ,          4      4      p. \/        \        P                  VP0                  ^ ,          4      n        VP;                  ^ V4       V EFD  p\=        VVRRR7      p\?        VW4       V'       d   \'        V	R	,          V
4      pMW,          p\        V\        \        34      '       d   VP                  p\        V\@        4      '       dz   \        V\@        4      '       dd   R F[  p\'        VV4      e   \'        VV4      f   V PC                  VVV4       K4  V PE                  \'        VV4      \'        VV4      V4       K]  	  K  \        V\@        4      '       g-   \        V\@        4      '       g   V PE                  VVV4       EK<  \G        R
4      h	  EK  \?        \        P                   ! V4      VP                  VP                  ,          V	4       V F  p
\I        WJW,          4       K  	  EK  	  VP                  PK                  4        VPL                   F  p
 \O        WJ4       K  	  VPL                  PK                  4        VPT                  PW                  4        FX  w  pp/ p\?        \        P                   ! V4      VP                  VP                  ,          V4       \I        VVVV,          4       KZ  	  VPT                  PK                  4        VPX                  P[                  4        F%  pV P]                  WV.,           4      '       d   K$   R# 	  VPX                  PK                  4        R#   \P        \R        \F        3 d     EK6  i ; i)a_  
This function patches module functions and methods. Specifically, only objects with their name in
self.to_autoreload will be considered for patching. If an object has been marked to be autoreloaded,
new_source_code gets executed in the old version's global environment. Then, replace the old function's
attributes with the new function's attributes.
zclass __autoreload_class__:
z    __code__Nz<string>execT)modedont_inherit__autoreload_class__z5adding or removing property decorations not supportedF)fgetfsetfdel)/r   r   r6   r   r   r:   rf   r   r4   r   r   staticmethodri   __func__textwrapdedentunparseindentdictr   r=  co_filenameparser   r   decorator_listpickleloadsdumpsinsertcompiler>  propertytry_patch_attrpatch_function
ValueErrorsetattrclearr   delattrAttributeError	TypeErrorr   r7   r   r   _patch_namespace)r^   r;  r   r   namespace_to_checkr   
seen_namesr   r  	local_envr   to_patch_to	func_code	is_method
global_envfilename	func_astswithout_decorator_listfunc_astcompiled_codeto_patch_fromr   r2  class_ast_nodelocal_env_classs   &&&                      r   _patch_namespace_inner&DeduperReloader._patch_namespace_inner  s    >>r!!33H=F!3!<!<V!D "u
"%"4"4E5zQ58z#9e$(*I;#:N:N(OPP"1X%T*E*EE5zQ&099$?kL++FGG"-"6"6K$OOCKK,DE	!$X!2393 ?(//!6C !I  [[
!*d33!%j!1J KT: 9 9#,,88" "! 
 !YYy12	tCOOYq\->->q-ABQQRUVV-3\\&,,yQR|:T-U* (* )?)D)DQ)G$$$Q(>? )H$+ (d%M 
> (/	:P0QSW(X(1!-,1LMM(5(>(>!+x88Z%x> > %=D 'T : B#*=$#?#G $ 3 3KPT U $ 3 3$+K$>$+M4$@$-!" %= (X>>z%xH H ++K	R(S A !*H KK,KK"4"="==
 "D.ioF "Y #5\ 	  "&&D*1 ' 	  "*-*@*@*F*F*H&J.0ON+0999
 &
OJ4OP +I 	$$&,,++-J((-DEE . 	# #Iz: s   V--WWc               $    V ^8  d   QhRRRRRR/# r:  r   )r   s   "r   r   r     s$     
 
#
/?
	
r   c                L     V P                  WR7      #   \         d     R# i ; i)z
Wrapper for patching all elements in a namespace as specified by the to_autoreload member variable.
Returns `true` if patching was successful, and `false` if unsuccessful.
)r   F)rm  r   )r^   r;  r   s   &&&r   r]   DeduperReloader._patch_namespace  s-    	..r.EE 		s    ##c                    V ^8  d   QhRRRR/# )r   r   r   r   r#   r   )r   s   "r   r   r     s     ) )* ) )r   c                   V P                   '       g   R# \        VRR4      ;p'       g   R# \        V4      ;pf   R#  \        VRRR7      ;_uu_ 4       pVP	                  4       pRRR4       RpT P                  P                  T4      ;p	'       d    \        P                  ! T	4      p
\        P                  ! X4      p\        P                   ! 4       pT;_uu_ 4        T P#                  T4       T P%                  Y4      '       d0   T P'                  4       '       d   T P)                  T4      '       d   RpRRR4       XT P                  T&   \+        4       T n        T#   + '       g   i     EL; i  \
         dO   p\        P                  ! R4      pTP                  RT R	T R
\        T4      P                   24        Rp?R# Rp?ii ; i  \
         d     R# i ; i  + '       g   i     L; i)za
Uses Deduperreload to try to update a module.
Returns `true` on success and `false` on failure.
FrE   Nr   r   r   r   r   r   r   T)r   r   r   r   r   r   r   r   r   r3   rE   r   r   r4   rM  r   suppress_build_dependency_graphr  r%  r]  r   r   )r^   r   modnamer   r   new_source_coder   r   patched_flagold_source_codeold_module_astnew_module_astr1   s   &&           r   maybe_reload_module#DeduperReloader.maybe_reload_module  s   
 |||"6:t<<<)&11E:	eS622a"#&&( 3 "4488AA?A!$?!;!$?!; %%'C,,^<**>JJ..00--f55#'L  +:w',.; 322 	&&|4F.ug^G9CPTUVPWP`P`Oab 	   s`   E2 E%E2 ,G >G G 4G E/	)E2 /E2 2G=AGGGG G0	c               $    V ^8  d   QhRRRRRR/# )r   	decoratorz.ast.Attribute | ast.Name | ast.Call | ast.expraccept_callsr#   r   r  r   )r   s   "r   r   r   J  s(      A  
	r   c                   \        V\        P                  4      '       d   VP                  .# \        V\        P                  4      '       d'   V'       d   V P                  VP                  R4      # R# \        V\        P                  4      '       g   R# V P                  VP                  R4      ;p'       d   W1P                  .,           # R# )zU
Generates a qualified name for a given decorator by finding its relative namespace.
FN)
r   r4   r   r   Call_separate_namefuncr   r~   r   )r^   r  r  prefs   &&& r   r  DeduperReloader._separate_nameJ  s     i**LL>!	388,,**9>>5AA)S]]33&&y>>4>>>***r   c               $    V ^8  d   QhRRRRRR/# )r   r   r   body_prefixesr  r   r#   r   )r   s   "r   r   r   `  s$      "3C	r   c                	R   T;'       g    . pV EF  pTp\        V\        P                  4      '       d0   V P                  VP                  W$P
                  .,           4       KU  \        V\        P                  \        P                  34      '       g   K  \        W$P
                  .,           4      p\        WT4      pVP                   FU  pV P                  VR 4      pV'       g   K  \        V4      p	V P                  P                  V	. 4      P                  V4       KW  	  EK  	  R # r   )r   r4   r  _gather_dependentsr   r   r   r   r   r@   rN  r  r   
setdefaultr   )
r^   r   r  r  r  rB   cur_dependency_noder  decorator_pathdecorator_path_tuples
   &&&       r   r  "DeduperReloader._gather_dependents`  s     &++H+3G'3<<00''m||n6TUg9M9M'NOO"=LL>#ABN"0"I$33	!%!4!4Y!E%',^'<$%%001ErJQQ' 4 " r   c                    V ^8  d   QhRRRR/# )r   new_astr   r   r#   r   )r   s   "r   r   r   w  s     5 5/H 5T 5r   c                8    V P                  VP                  4      # )z
Wrapper function for generating dependency graph given some AST.
Returns `true` on success. Returns `false` on failure.
Currently, only returns `true` as we do not block on failure to build this graph.
)r  r   )r^   r  s   &&r   ru  'DeduperReloader._build_dependency_graphw  s     &&w||44r   )r   r   r   r   r&   )rE   rF   rG   rH   rI   rs   rT  r   setterr   rk   r   rE  r   ri   r   r  r  r%  r$  r#  r.  rm  r]  r|  r  r  ru  rK   r   r   r   r   r      s     O O ^^ 9< +,  
2 
2 9 9v4l
rh
)V,.5 5r   r   )'
__future__r   r4   r   r   r[   r   r   rO  r   r   rG  typesr   typingr   r   r   r   collections.abcr	   r
   7IPython.extensions.deduperreload.deduperreload_patchingr   r   r   r   r   r   r   TDefinitionAstr   r'   r@   rM   NodeVisitorrk   r   r   r   r   r   <module>r     s    " 
     	   
   7 7 / 


	
**	 ..	 **		
 --	 .<"Z "(/: /0 !  !F 4P52 P5r   