
    +j2                         S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
Jr  S SKJrJrJrJr   " S S5      r " S S5      rSS\S	\4S
 jjrg)    N)Enum)Optional
get_originget_argsget_type_hintsc                   <    \ rS rSrSrS rS rS\S\\   4S jr	Sr
g	)
TypeTracker   zOTracks types discovered during stub generation for automatic import generation.c                 B    0 U l         1 SkU l        [        5       U l        g )N>   AnySetintsetstrDictListNoneboolcastdictlisttypeTupleUnionbytesfloattupleobjectr   Sequence
NamedTuple)discovered_typesbuiltin_typesr   already_imported)selfs    @/home/wildlama/comfy/ComfyUI/comfy_api/internal/async_to_sync.py__init__TypeTracker.__init__   s#     "
2 E 	    c                 J   Ub  U[        S5      L a  g[        USS5      nU(       a  X R                  ;   d  X R                  ;   a  g[        USS5      n[        USU=(       d    S5      nUS:X  a  gUS:X  a  US;   a  gU(       a   US	;  a  U(       a  X44U R                  U'   gggg)
z:Track a type annotation and record its module/import info.N__name__
__module____qualname__ typingtypes)	UnionTypeGenericAlias)builtins__main__)r   getattrr"   r#   r!   )r$   
annotation	type_namemodulequalnames        r%   
track_typeTypeTracker.track_type/   s    tDz!9 J
D9	+++y<Q<Q/Q \48:~yBG X W.K!Kf$<<4:3E%%i0  =6r(   main_module_namereturnc                    / n0 n[        U R                  R                  5       5       H<  u  nu  pVU(       a  XQ:X  a  M  XS;  a  / X5'   XCU   ;  d  M)  X5   R                  U5        M>     [        UR                  5       5       Hh  u  pW[	        U5      S:X  a  UR                  SU SUS    35        M0  UR                  SU SSR                  [        [        U5      5      5       35        Mj     U$ )z4Generate import statements for all discovered types.   from  import r   , )sortedr!   itemsappendlenjoinr   )r$   r;   importsimports_by_moduler6   r7   r8   r/   s           r%   get_importsTypeTracker.get_importsL   s    -3D4I4I4O4O4Q-R)I)F$>.,.!)& 99!)00; .S $$5$;$;$=>MF5zQvhhuQxjABvhhtyyE
AS7T6UVW	 ? r(   )r#   r"   r!   N)r*   r+   r,   __firstlineno____doc__r&   r9   r   r   rI   __static_attributes__ r(   r%   r	   r	      s'    Y
<F:C DI r(   r	   c                      \ rS rSr% SrSr\\R                  R                     \
S'   \R                  " 5       rSr\S#S\R                  R                  4S jj5       r\S 5       r\S$S	\S\4S
 jj5       r\ S#S\\   S\4S jj5       r\S 5       r\S\4S j5       r\   S%S\R4                  S\S\\   S\\   S\4
S jj5       r\  S&S\S\S\\   S\4S jj5       r\S	\S\S\\   4S j5       r \S	\S\\!\\4      4S j5       r"\  S'S\S\S\S\\   S\\   4
S jj5       r#\ S(S\S\S\\   4S jj5       r$\S\\   S\\   4S j5       r%\S	\S \SS4S! j5       r&S"r'g))AsyncToSyncConvertere   zU
Provides utilities to convert async classes to sync classes with proper type hints.
N_thread_poolFr<   c                 \   U R                   (       a   U R                  c   S5       eU R                  $ U R                     U R                   (       d*  [        R                  R                  USS9U l        SU l         SSS5        U R                  c   eU R                  $ ! , (       d  f       N)= f)zLGet or create the shared thread pool with proper thread-safe initialization.Nz!Thread pool should be initializedasync_to_sync_)max_workersthread_name_prefixT)_thread_pool_initializedrR   _thread_pool_lock
concurrentfuturesThreadPoolExecutor)clsrU   s     r%   get_thread_pool$AsyncToSyncConverter.get_thread_pooln   s     ''##/T1TT/### ""//#-#5#5#H#H +@P $I $  04, # +++ #"s   <B
B+c                    ^^^^^ [         R                  " 5       mSSS.mUUUUU4S jnU R                  5       nUR                  U5      nUR	                  5         TS   b  TS   eTS   $ )z
Run an async function in a separate thread from the thread pool.
Blocks until the async function completes.
Properly propagates contextvars between threads and manages event loops.
N)result	exceptionc            	      F  > [         R                  " 5       n [         R                  " U 5         UUU	4S jnTR                  U R                  U" 5       5      nUT
S'    [         R                  " U 5      nU H  nUR                  5         M     U(       a%  U R	                  [         R                  " USS065        U R                  5         [         R                  " S 5        g ! [
         a  nUT
S'    S nANS nAff = f! [
         a     NOf = f!  [         R                  " U 5      nU H  nUR                  5         M     U(       a%  U R	                  [         R                  " USS065        O! [
         a     Of = fU R                  5         [         R                  " S 5        f = f)Nc                  0   >#    T" T 0 TD6I S h  vN $  N7fNrN   )args	coro_funckwargss   r%   run_with_contextYAsyncToSyncConverter.run_async_in_thread.<locals>.run_in_thread.<locals>.run_with_context   s     !*D!;F!;;;;s   r`   ra   return_exceptionsT)
asyncionew_event_loopset_event_looprunrun_until_complete	Exception	all_taskscancelgatherclose)looprh   r`   ependingtaskre   contextrf   rg   result_containers         r%   run_in_thread?AsyncToSyncConverter.run_async_in_thread.<locals>.run_in_thread   sc   ))+D""4(!-< !T%<%<>N>PQ-3 *%//5G ' !( //#NNGLtL 

 &&t,/  201 -2  ! %//5G ' !( //#NNGLtL !  

 &&t,sa   .C AC; 
C8)C3.D 3C88D ;
DDF AE)(F )
E63F 5E66*F ra   r`   )contextvarscopy_contextr]   submitr`   )	r\   rf   re   rg   r{   thread_poolfuturery   rz   s	    ```   @@r%   run_async_in_thread(AsyncToSyncConverter.run_async_in_thread   sw     **, -1t!D&	- &	-R ))+##M2 K(4";//))r(   async_classc                 N  ^ ^ SnT R                  U5        TR                  TR                  UTS.nUU 4S jnXTS'   [        R                  " T[        R
                  S9 H  u  pgUR                  S5      (       a  M  [        R                  " U5      (       a&  [        R                  " U5      US.S j5       nXU'   M^  [        R                  " U5      US.S	 j5       n	XU'   M     [        R                  " TS
 5       H  u  pjS nU" Xj5      XF'   M     [        U[        4U5      nU$ )z
Creates a new class with synchronous versions of all async methods.

Args:
    async_class: The async class to convert
    thread_pool_size: Size of thread pool to use

Returns:
    A new class with sync versions of all async methods
ComfyAPISyncStub)rL   r+   r,   __orig_class__c                   > T" U0 UD6U l          [        T5      nUR                  5        GHz  u  pV[        U R                   U5      (       a  [        U R                   U5      n[        US5      (       ai  SSKJn  [        Xx5      (       aE   TR                  UR                  5      n	[         R#                  U	5      n
Xzl         [%        XU
5        M  [%        XU5        M  M  [        U[&        5      (       d  M  [        TUR(                  5      (       d  M  [        TUR(                  5      nSSKJn   [+        X5      (       a  UR-                  5       nOU" 5       nTR                  U5      n	[         R#                  U	5      n
Xl         [%        XU
5        [%        U R                   X\5        GM}     [        R2                  " U R                   5       H  u  pUR5                  S5      (       d  [        X5      (       a  M-  [        U[         5      (       d  MD  [        U[6        [8        [:        [<        [>        [@        [B        45      (       a  Mz  SSKJn  [        Xx5      (       d  M   TR                  UR                  5      n	[         R#                  U	5      n
Xzl         [%        XU
5        M     g ! [         aZ    0 n[        [        R
                  " T5      5       H1  n[        US5      (       d  M  UR                  UR                  5        M3      GNf = f! [         a    [%        XU5         GM  f = f! [         a(  n[.        R0                  " SU SU 35         S nAGM+  S nAff = f! [         a    [%        XU5         GM  f = f)N__annotations__	__class__r   )ProxiedSingletonzFailed to create instance for : _)"_async_instancer   rp   reversedinspectgetmrohasattrupdater   rC   r4   comfy_api.internal.singletonr   
isinstancecreate_sync_classr   r   __new__setattrr   r*   
issubclassget_instanceloggingwarning
getmembers
startswithr   r   r   r   r   r   r   )r$   re   rg   all_annotations
base_class	attr_name	attr_typeattrr   sync_attr_class	sync_attrinner_classasync_instancerv   namer   r\   s                  r%   r&   8AsyncToSyncConverter.create_sync_class.<locals>.__init__   s   #.#?#?D 
K #1"= )8(=(=(?$	4//;;"4#7#7CDt[11Q%d==?252G2G2W,2NN?,K	<@ 9 ' C $DT:! 2( ")T22";	0B0BCC*1+y?Q?Q*RKU"#-k#L#L5@5M5M5ON5@]N 362G2G2T,2NN?,K	<J 9 ' C '(<(<i X[ )@h &001E1EF
??3''74+>+> dF++J3UD$eD5 5 N!$996.1.C.CDNN.SO(.(GI8<5#D	:% G{  K #%"*7>>++F"GJz+<=='..z/I/IJ #H	K2 $- ? ' > >?< $- " '&DYKrRSQT$U!" !""2  ) 6#D556sV   J$ 
AL/A6L)AM$=L%LLL&%L&)
M3MMM98M9r&   	predicater   )_method_namec                b    [        U R                  U5      n[        R                  " U/UQ70 UD6$ rd   )r4   r   rP   r   )r$   r   re   rg   async_methods        r%   sync_method;AsyncToSyncConverter.create_sync_class.<locals>.sync_methodD  s:    #*4+?+?#NL/CC$'+/5 r(   c                >    [        U R                  U5      nU" U0 UD6$ rd   )r4   r   )r$   r   re   rg   methods        r%   proxy_method<AsyncToSyncConverter.create_sync_class.<locals>.proxy_methodO  s$    $T%9%9<HF!42622r(   c                 "    [        U [        5      $ rd   r   propertyxs    r%   <lambda>8AsyncToSyncConverter.create_sync_class.<locals>.<lambda>Y  s    :a#:r(   c                 `   ^  U 4S jnU 4S jn[        X!R                  (       a  U5      $ S 5      $ )Nc                 |   >^ [        U R                  T5      m[        R                  " T5      (       a  U4S jnU$ T$ )Nc                  8   > [         R                  " T/U Q70 UD6$ rd   )rP   r   )re   rg   values     r%   sync_fn^AsyncToSyncConverter.create_sync_class.<locals>.make_property.<locals>.getter.<locals>.sync_fna  s)    #7#K#K %$(,$06$ r(   )r4   r   r   iscoroutinefunction)r$   r   r   r   s     @r%   getterMAsyncToSyncConverter.create_sync_class.<locals>.make_property.<locals>.getter]  s7    #D$8$8$?E22599
  ' Lr(   c                 4   > [        U R                  TU5        g rd   )r   r   )r$   r   r   s     r%   setterMAsyncToSyncConverter.create_sync_class.<locals>.make_property.<locals>.setteri  s    D00$>r(   )r   fset)r   prop_objr   r   s   `   r%   make_property=AsyncToSyncConverter.create_sync_class.<locals>.make_property\  s(    
!?  --JJTJJr(   )r]   rL   r+   r   r   
isfunctionr   r   	functoolswrapsr   r   )r\   r   thread_pool_sizesync_class_namesync_class_dictr&   r   r   r   r   propr   
sync_classs   ``           r%   r   &AsyncToSyncConverter.create_sync_class   s4    -,- #**%00+)	
[	6z '/
# $..7#5#5
LD s## **622(:>  ) )4% (;? 3 )3
 )5%5
: ",,:
JDK$ %2$$=O!-
2 /F9oF
r(   type_trackerc                    U[         R                  R                  L d  U[         R                  R                  L a  gU[	        S5      L a  gU(       a  UR                  U5         [        U5      n[        U5      nUb  U(       a  UR                  U5        [        US[        U5      5      nSU;   a  UR                  S5      S   n[        U5      S:X  d  US:X  a  S	nU(       aZ  / nU H;  nU(       a  UR                  U5        UR                  U R                  Xr5      5        M=     U S
SR                  U5       S3$ U$  [!        US5      (       a  [!        US5      (       a  UR"                  n[!        US5      (       a  UR$                  O[        U5      R                  S5      S   n/ nUR&                   H#  nUR                  U R                  Xr5      5        M%     U S
SR                  U5       S3$ [!        US5      (       a  UR$                  $ [!        US5      (       a  [!        US5      (       a  UR(                  $ [        U5      nUR+                  S5      (       a  UR-                  S5      (       a  USS nS H)  n	UR+                  U	5      (       d  M  U[/        U	5      S nM+     US;   a  gUS:X  a  gU$ ! [        [        4 a     GNf = f)zFConvert a type annotation to its string representation for stub files.r   Nr   r*   .z<class 'types.UnionType'>r0   r   [rA   ]
__origin____args__'r>   r+   r,   z<class 'z'>   )ztyping.z	builtins.ztypes.)_emptyzinspect._emptyNoneType)r   	Parameterempty	Signaturer   r9   r   r   r4   r   splitrD   _format_type_annotationrF   AttributeError	TypeErrorr   r   r*   r   r,   r   endswithrE   )
r\   r5   r   originre   origin_nameformatted_argsargtype_strprefixs
             r%   r   ,AsyncToSyncConverter._format_type_annotationu  s    '++111W..444 d# ##J/ 	
+FJ'D! ++F3 &fj#f+F+%"-"3"3C"8"<K v;"==P[A[")K %'N#'(33C8&--c.I.I#.\]	  $
 *]!DIIn,E+FaHH&&3 "> :|,,Z1P1P**F 6:.. [&&s+A.  D!**C77JK + "]!DIIdO#4A66 :z**&&& :|,,^1T1T*** z? z**x/@/@/F/F"~H 9F""6**#CKM2 9
 33 z!c 	* 		s   $CJ: =J: :KKc                 x    [        US5      (       a(  [        UR                  5      S:  a  UR                  S   $ U$ )z;Extract the actual return type from a Coroutine annotation.r      )r   rE   r   )r\   r5   s     r%   _extract_coroutine_return_type3AsyncToSyncConverter._extract_coroutine_return_type  s:     :z**s:3F3F/G!/K&&q))r(   c                     U[         R                  R                  L a  gUc  g[        U[        5      (       a  SU 3$ U0 :X  a  gU/ :X  a  gSU 3$ )z2Format a parameter's default value for stub files.r-   z = Nonez = z = {}z = [])r   r   r   r   r   )r\   default_values     r%   _format_parameter_default.AsyncToSyncConverter._format_parameter_default  sa     G--333"t,,((b b ((r(   sig	skip_self
type_hintsc                    / nUc  0 n[        UR                  R                  5       5       H  u  nu  pxUS:X  a   US:X  a  U(       a  UR                  S5        M.  UR	                  XxR
                  5      n	U R                  X5      n
U R                  UR                  5      nU	[        R                  R                  L a  UR                  U SU 35        M  UR                  U SU
 U 35        M     SR                  U5      $ )z(Format method parameters for stub files.r   r$   z: Anyr   rA   )	enumerate
parametersrC   rD   getr5   r   r   defaultr   r   r   rF   )r\   r   r   r   r   paramsi
param_nameparamr5   r   default_strs               r%   _format_method_parameters.AsyncToSyncConverter._format_method_parameters  s     J&/0D0D0F&G"A"
Av*.9f% (^^J8H8HI
66zP ";;EMMJ !2!2!8!88MMZLk]"CDMMZL8*[M"JK 'H" yy  r(   method_nameis_asyncc                    [         R                  " U5      n SSKJn  U" U5      nUR                  SUR                  5      nU(       a,  [         R                  " U5      (       a  U R                  U5      nU R                  XWUS9n	U R                  X5      n
U[         R                  R                  L a  Sn
SU SU	 SU
 S	3$ ! [         a    0 n Nf = f)
z4Generate a complete method signature for stub files.r   r   r<   r   r   r   def () -> : ...)r   	signaturer.   r   rp   r   return_annotationr   r   r  r   r   r   )r\   r  r   r	  r   r   r   r   r  
params_strreturn_types              r%   _generate_method_signature/AsyncToSyncConverter._generate_method_signature  s     '	-'/J 'NN8S5J5JK33F;; # B BCT U 223\h2i
 112CR 1 1 7 77 Kk]!J<u[MGG#  	J	s   C CCc                   ^ / nUR                  S5        UR                  S:w  Ga  [        R                  " U5      n/ nU(       Ga  [	        USS5      n[        [        R                  " U5      5       H  u  px[        U[        5      (       d  M  Ub  Xv;  a  XrR                  ;  a  M5  [        U[        5      (       a?  [        US5      (       a.  UR                  U5        UR                  R                  U5        M  [        U[        5      (       d  M  US:w  d  M  UR                  U5        UR                  R                  U5        M     U(       aA  SR!                  UR"                  /U-   5      n	UR                  SUR                   S	U	 35        O+UR                  SUR                   S	UR"                   35        UR%                  UR'                  UR                  S
95        [        [        R                  " U5      S5      (       ah  [        R                  " U5      R"                  n
SU
;   aB  U
R)                  S5      S   m[+        U4S jU 5       5      (       d  UR                  ST 35        U$ )z-Generate import statements for the stub file.z[from typing import Any, Dict, List, Optional, Tuple, Union, Set, Sequence, cast, NamedTupler2   __all__N_fieldsr   rA   r?   r@   )r;   r*   r   r   c              3   J   >#    U  H  oR                  S T 35      v   M     g7f)r?   N)r   ).0impbase_modules     r%   	<genexpr>9AsyncToSyncConverter._generate_imports.<locals>.<genexpr>q  s"     TGS>>E+*?@@Gs    #import )rD   r+   r   	getmoduler4   rB   r   r   r   r!   r   r   r   r#   addr   rF   r*   extendrI   r   any)r\   r   r   rG   r7   additional_types
module_allr   objtype_importsmodule_namer  s              @r%   _generate_imports&AsyncToSyncConverter._generate_imports4  s   
  	i	

 !!Z/&&{3F!$VY=
!'(:(:6(B!CID!#t,, &1d6L#+H+HH ( &c511gc96M6M,33D9(99==dC'T22tv~,33D9(99==dC% "D(  #yy+*>*>)?BR)RS{'='=&>h|nUVK2238K<P<P;QR 	$$k6L6L$M	

 7$$[1:>>!++K8AAKk!)//4Q7TGTTTNNW[M#:;r(   c                 |   / n [        U5      n[        [        R                  " U5      5       Hx  u  pE[        U[        5      (       a*  UR                  S5      (       d  UR                  XE45        MD  XC;   d  MK  X4   n[        U[        5      (       d  Mf  UR                  XF45        Mz     U$ ! [         a    0 n Nf = f)z5Extract class attributes that are classes themselves.r   )	r   rp   rB   r   r   r   r   r   rD   )r\   r   class_attributesr   r   r   r5   s          r%   _get_class_attributes*AsyncToSyncConverter._get_class_attributesv  s     	'4J
 !!3!3K!@AJD$%%dooc.B.B ''5#'-
j$//$++T,>? B    	J	s   B, ,B;:B;r   r   indentc                    / nUR                  U SU S35        [        US5      (       a?  UR                  (       a.  UR                  U R	                  UR                  U S35      5        [        US5      (       a   [        US5      n[        R                  " U5      n SSKJ	n  U" U5      n	U R                  XyUS9n
[        US5      (       a?  UR                  (       a.  UR                  U R	                  UR                  U S35      5        UR                  U S	U
 S
35        Sn[        [        R                  " U[        R                   S95       H  u  pUR#                  S5      (       a  M  Sn UR                  (       a.  UR                  U R	                  UR                  U S35      5        U R%                  XSUS9nUR                  U SU 35        M     U(       d  UR                  U S35        U$ ! [         a    0 n	 GN[f = f! [        [        4 a    UR                  U S35         GNf = f! [        [        4 a    UR                  U SU S35         GM  f = f)z!Generate stub for an inner class.class zSync:rL       r&   r   r  r      def __init__() -> None: ...4    def __init__(self, *args, **kwargs) -> None: ...Fr   r   Tr	  r       def (self, *args, **kwargs): ...z    pass)rD   r   rL   r#  _format_docstring_for_stubr4   r   r  r.   r   rp   r  
ValueErrorr   rB   r   r   r   r  )r\   r   r   r0  r   
stub_linesinit_methodinit_sigr   
init_hintsr  has_methodsr  r   
method_sigs                  r%   _generate_inner_class_stub/AsyncToSyncConverter._generate_inner_class_stub  sz    
VHF4&67 4##..t||xt_M
 4$$%dJ7",,[9$5!/!<J
 !::, ; 
 ;	22{7J7J%%66'//F84
 !!h/
|>J #)tw/A/AB$
K %%c**K>>%%66v~~&QUW !;;$\ < 
 !!VHD"=>#$
. 12e ! $!#J$" 	* !!hRS2 	* !!hh{m3OP sJ   <"H G9 -A7H 2A&H79H	H H		H $H43H47'I#"I#	docstringc                 b   U(       d  / $ [         R                  " U5      R                  5       nUR                  S5      n/ nUR	                  U S35        U H@  nUR                  5       (       a  UR	                  U U 35        M/  UR	                  S5        MB     UR	                  U S35        U$ )zHFormat a docstring for inclusion in a stub file with proper indentation.
z"""r-   )textwrapdedentstripr   rD   )r\   rD  r0  dedentedlinesr`   lines          r%   r:  /AsyncToSyncConverter._format_docstring_for_stub  s    
 I ??9-335 t$ n%Dzz||/0b!	  	n%r(   stub_contentc                 P   / nU H  nUR                  S5      (       a  UR                  U5        M,  UR                  5       R                  S5      (       a<  UR                  5       R                  S5      (       a  SU;  a  UR	                  SS5      nUR                  U5        M     U$ )z6Post-process stub content to fix any remaining issues.)r?   r   r  r  r  z -> None: ...)r   rD   rI  r   replace)r\   rN  	processedrL  s       r%   _post_process_stub_content/AsyncToSyncConverter._post_process_stub_content  s     	 D344  & 

''//JJL))'224' ||G_=T" !" r(   r   c           	          UR                   S:X  a  g[        R                  " U5      nU(       d  gUR                  nU(       d  g[        R
                  R                  U5      n[        R
                  R                  US5      n[        R                  " USS9  [        R
                  R                  U5      nUR                  S5      (       a  USS n[        R
                  R                  XbR                   S35      n[        5       n	/ n
[        U
5      nU
R                  S	5        U
R                  S
UR                   S35        UR                  (       a+  U
R!                  U R#                  UR                  S5      5         UR$                  n[        R&                  " U5      n SSKJn  U" U5      nU R/                  XU	S9n[1        US5      (       a<  UR                  (       a+  U
R!                  U R#                  UR                  S5      5        U
R                  SU S35        U
R                  S	5        U R7                  U5      nU H9  u  nnU R9                  UUU	S9nU
R!                  U5        U
R                  S	5        M;     [;        5       n[=        [        R>                  " U[        R@                  S95       H  u  nnURC                  S5      (       d  UU;   a  M$  URE                  U5         U RG                  UUSU	S9nUR                  (       a+  U
R!                  U R#                  UR                  S5      5        U
R                  SU 35        U
R                  S	5        M     [=        [        R>                  " US 5      5       Hx  u  nnU
R                  S5        U
R                  SU S35        URH                  (       a*  U
R                  SU S35        U
R                  SU S35        U
R                  S	5        Mz     0 n W" U5      n[=        URS                  5       5       H]  u  nnU HQ  u  nnUU:X  d@  [1        US!5      (       a  UR                  U:X  d  [U        U[V        5      (       d  MD  UU:X  d  ML  UUU'   MS     M_     U H0  u  nnURY                  UU5      nU
R                  SU S"U S#35        M2     U
R                  S	5        U R[                  X5      n [;        5       n!/ n"U  HF  n#U#U!;  a$  U!RE                  U#5        U"R                  U#5        M-  [\        R^                  " S$U# 35        MH     U"XUS%-   & U Ra                  U
5      n
[c        US&5       n$U$Re                  S'R                  U
5      5        SSS5        [\        Rf                  " S(U 35        g! [,         a    0 n GNf = f! [2        [4        4 a    U
R                  S5         GNf = f! [2        [4        4 a+    U
R                  SU S35        U
R                  S	5         GM[  f = f! [,         aZ    0 n[K        [        RL                  " U5      5       H1  n[1        US 5      (       d  M  URO                  URP                  5        M3      GNmf = f! , (       d  f       GN	= f! [,         aa  n%[\        Rh                  " S)UR                   S"[W        U%5       35        SSK5n&[\        Rh                  " U&Rm                  5       5         Sn%A%gSn%A%ff = f)*zO
Generate a .pyi stub file for the sync class to help IDEs with type checking.
r3   N	generatedT)exist_okz.pyz.pyir-   r2  :r3  r   r  r  rL   r4  r5  r6  )r   r   r   r7  r8  r9  c                 "    [        U [        5      $ rd   r   r   s    r%   r   9AsyncToSyncConverter.generate_stub_file.<locals>.<lambda>  s    *Q:Qr(   z    @propertyz(self) -> Any: ...z    @z.setterz(self, value: Any) -> None: ...r   r*   r   SynczDuplicate import detected: r>   wrF  zGenerated stub file: zError generating stub file for )7r+   r   r!  __file__ospathdirnamerF   makedirsbasenamer   r*   r	   rE   rD   rL   r#  r:  r&   r  r.   r   rp   r  r   r;  r   r.  rB  r   rB   r   r   r   r"  r  r   r   r   r   r   rC   r   r   r   r*  r   r   rR  openwriteinfoerror	traceback
format_exc)'r\   r   r   r7   module_path
module_dirstub_dirr)  sync_stub_pathr   rN  imports_placeholder_indexr=  init_signaturer   r?  r  r-  r   r   inner_class_stubprocessed_methodsr   rA  r   attribute_mappingsr   r   r   r   
class_name
class_typerG   seenunique_importsr  frv   rg  s'                                          r%   generate_stub_file'AsyncToSyncConverter.generate_stub_file  s   
G	2%%3&&{3F //K 5Jww||J<H KK40''**;7K##E**)#2.WW\\(7J7J6K44PQN '=LL ),L(9%# &)<)<(=Q ?@ ""##22;3F3FO
)22!(!2!2;!?$5!/!<J
 !::" ; 
 ;	22{7J7J ''66{7J7JFS ##&7
|>$RS #  #88E /
d#&#A#A$\ $B $  ##$45##B' / !$ &"";':L:LM!f ??3''43D+D!%%d+,!$!?!?ft, "@ "J
 ~~$++::6>>6R !''$zl(;< ''++!: %"";0QR
d ##O4##htf4F$GH99 ''%vW(=> ''"4&(GH ##B' "$K"0"= )//D/D/F(G$	9.>*J
 "Z/#Iz::y?Q?QU_?_&y#669
;R9B*:6 /? )H +;&
J.22:zJ	 ##d9+R
|4$HI +; # ++KFG 5DNd?HHSM"))#.OO&A#$GH   5NQR5RS
 99,GL nc*a		,/0 + LL00@ABQ ! $!#J$ 	* ##JV #I. , ''(4&8T(UV ''++,4  K"$"*7>>++F"GJz+<=='..z/I/IJ #HKf +*
  	2MM1*2E2E1FbQQ MM)..011	2s   Z Z Z D=Z "V6 &V# 4A2V6 &CZ 3A3W&B#Z 
X A!Z 7Z ?C!Z  !Z!Z #V3/V6 2V33V6 6!WZ WZ 6XZ XZ =Z Z <Z ?Z  Z 
ZZ 
\ A[;;\ )r   rd   
   )TNN)FN)r3  N)r3  )(r*   r+   r,   rK   rL   rR   r   rY   rZ   r[   r   	threadingLockrX   rW   classmethodr]   r   r   r   r	   r   r   r   r   r   r   r   r   r  r  r   r*  r   r.  rB  r:  rR  rw  rM   rN   r(   r%   rP   rP   e   s    EIL(:--@@AH!($ *2D2D2W2W    & >* >*@ oD o$ o ob ?Cb'/'<b	b bH   ) ) )  %).2!! ! TN	!
 {+! 
! !> 
 .2HH 	H
 {+H 
H HB ??.9?	c? ?B    eCI>N9O    , 
 .2MM M 	M
 {+M 
cM M^ +1%(	c 4 d3i DI  . K2T K2t K2 K2 K2r(   rP   r   r<   c                 ,    [         R                  X5      $ )z
Creates a sync version of an async class

Args:
    async_class: The async class to convert
    thread_pool_size: Size of thread pool to use

Returns:
    A new class with sync versions of all async methods
)rP   r   )r   r   s     r%   r   r     s      11+PPr(   ry  )rk   concurrent.futuresrY   r}   r   r   r   r^  rG  r{  enumr   r.   r   r   r   r   r	   rP   r   r   rN   r(   r%   <module>r     sY          	    A AT Tnw2 w2tQ4 Q Qr(   