
    +j2                         d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
mZ d dlmZmZmZmZ  G d d          Z G d d          Zdd	ed
efdZdS )    N)Enum)Optional
get_originget_argsget_type_hintsc                   :    e Zd ZdZd Zd Zdedee         fdZdS )TypeTrackerzOTracks types discovered during stub generation for automatic import generation.c                 L    i | _         h d| _        t                      | _        d S )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__zTypeTracker.__init__   s5     "
 
 
2 EE 	    c                 "   ||t          d          u rdS t          |dd          }|r|| j        v s	|| j        v rdS t          |dd          }t          |d|pd          }|dk    rdS |dk    r|dv rdS |r|d	vr|r||f| j        |<   dS dS dS dS )
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_typezTypeTracker.track_type/   s   tDzz!9!9F J
D99	 	+++yD<Q/Q/QF \488:~yBGG XF W.K!K!KF 	Ff$<<< F4:H3E%i000	F 	F<<F Fr&   main_module_namereturnc                 "   g }i }t          | j                                                  D ]?\  }\  }}|r||k    r||vrg ||<   |||         vr||                             |           @t          |                                          D ]\  }}t	          |          dk    r"|                    d| d|d                     :|                    d| dd                    t          t          |                                          |S )z4Generate import statements for all discovered types.   from  import r   , )sortedr    itemsappendlenjoinr   )r#   r8   importsimports_by_moduler4   r5   r6   r-   s           r$   get_importszTypeTracker.get_importsL   s?   -3D4I4O4O4Q4Q-R-R 	< 	<)I) F.>$>$>...,.!&) 1& 999!&)00;;; $$5$;$;$=$=>> 	X 	XMFE5zzQAvAAuQxAABBBBVvVVtyyE

ASAS7T7TVVWWWWr&   N)	r(   r)   r*   __doc__r%   r7   r   r   rF    r&   r$   r	   r	      sa        YY
 
 
<F F F:C DI      r&   r	   c                      e Zd ZU dZdZeej        j                 e	d<    e
j                    ZdZed$dej        j        fd            Zed             Zed%d	edefd
            Ze	 d$dee         defd            Zed             Zedefd            Ze	 	 	 d&dej        dedee         dee         def
d            Ze	 	 d'dededee         defd            Zed	ededee         fd            Zed	edee eef                  fd            Z!e	 	 d(dedededee         dee         f
d            Z"e	 d)dededee         fd            Z#ed ee         dee         fd!            Z$ed	ed"eddfd#            Z%dS )*AsyncToSyncConverterz]
    Provides utilities to convert async classes to sync classes with proper type hints.
    N_thread_poolFr9   c                    | j         r| j        
J d            | j        S | j        5  | j         s-t          j                            |d          | _        d| _         ddd           n# 1 swxY w Y   | j        J | j        S )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_initializedrK   _thread_pool_lock
concurrentfuturesThreadPoolExecutor)clsrN   s     r$   get_thread_poolz$AsyncToSyncConverter.get_thread_pooln   s     ' 	$#//1T///## " 	4 	4/ 4#-#5#H#H +@P $I $ $  04,	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 +++s   5A((A,/A,c                     t          j                    dddfd}|                                 }|                    |          }|                                 d         d         d         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            	      .   t          j                    } t          j        |            	 	fd}                    | j         |                      }|
d<   n# t
          $ r}|
d<   Y d }~nd }~ww xY w	 t          j        |           }|D ]}|                                 |r$|                     t          j        |ddi           n# t
          $ r Y nw xY w| 	                                 t          j        d            d S # 	 t          j        |           }|D ]}|                                 |r$|                     t          j        |ddi           n# t
          $ r Y nw xY w| 	                                 t          j        d            w xY w)Nc                  $   K     i  d {V S NrH   )args	coro_funckwargss   r$   run_with_contextzYAsyncToSyncConverter.run_async_in_thread.<locals>.run_in_thread.<locals>.run_with_context   s.      !*D!;F!;!;;;;;;;;r&   rX   rY   return_exceptionsT)
asyncionew_event_loopset_event_looprunrun_until_complete	Exception	all_taskscancelgatherclose)loopr`   rX   ependingtaskr]   contextr^   r_   result_containers         r$   run_in_threadz?AsyncToSyncConverter.run_async_in_thread.<locals>.run_in_thread   s   )++D"4(((!-< < < < < < < !T%<>N>N>P>PQQ-3 ** 2 2 201 ------2
%/55G ' & &  //#NGLtLL   !   D 

 &t,,,,,%%/55G ' & &  //#NGLtLL   !   D 

 &t,,,,sg   /A D 
A3$A.)D .A33D 7AC 
CCFAEF
E(%F'E((,FrY   rX   )contextvarscopy_contextrV   submitrX   )	rU   r^   r]   r_   rr   thread_poolfuturerp   rq   s	    ```   @@r$   run_async_in_threadz(AsyncToSyncConverter.run_async_in_thread   s     *,, -1t!D!D&	- &	- &	- &	- &	- &	- &	- &	- &	-R ))++##M22 K(4";//))r&   
   async_classc                 0    d}                      |           j        j        |d} fd}||d<   t          j        t          j                  D ]z\  }}|                    d          rt          j        |          r&t          j	        |          |dd            }|||<   Ut          j	        |          |dd	            }	|	||<   {t          j        d
           D ]\  }}
d } |||
          ||<   t          |t          f|          }|S )a#  
        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)rG   r)   r*   __orig_class__c                      |i || _         	 t                    }n`# t          $ rS i }t          t	          j                            D ],}t          |d          r|                    |j                   -Y nw xY w|	                                D ]\  }}t          | j         |          rt          | j         |          }t          |d          rddlm} t          ||          ro	                     |j                  }	t                               |	          }
||
_         t%          | ||
           # t          $ r t%          | ||           Y w xY wt%          | ||           t          |t&                    rt          |j                  rt          |j                  }ddlm} 	 t+          ||          r|                                }n
 |            }                    |          }	t                               |	          }
||
_         t%          | ||
           t%          | j         ||           # t          $ r%}t/          j        d| d|            Y d }~d }~ww xY wt	          j        | j                   D ] \  }}|                    d          st          | |          r,t          |t                     rt          |t6          t8          t:          t<          t>          t@          tB          f          sddlm} t          ||          ro	                     |j                  }	t                               |	          }
||
_         t%          | ||
           # t          $ r t%          | ||           Y w xY wd S )N__annotations__	__class__r   )ProxiedSingletonzFailed to create instance for : _)"_async_instancer   rg   reversedinspectgetmrohasattrupdater   r@   r2   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#   r]   r_   all_annotations
base_class	attr_name	attr_typeattrr   sync_attr_class	sync_attrinner_classasync_instancerm   namerz   rU   s                  r$   r%   z8AsyncToSyncConverter.create_sync_class.<locals>.__init__   s1   #.;#?#?#?D 
K #1"="= K K K #%"*7>++F+F"G"G K KJz+<== K'..z/IJJJK K	K )8(=(=(?(? 1" 1"$	94/;; 0""4#7CCDt[11 ;QQQQQQ%d,<== ;?252G2G2W2W,2NN?,K,K	<@	 9 'i C C C C#, ? ? ? 'i > > > > >?
 $D)T::: ")T22 "";	0BCC "*1+y?Q*R*RKUUUUUU"#-k;K#L#L !C5@5M5M5O5ONN5@[]]N 362G2G2T2T,2NN?,K,K	<J	 9 'i C C C '(<i X X X X#, " " " '$UY$U$URS$U$U!" !" !" !" !" !" !" !"" &01EFF 6 6
d??3'' 74+>+>  dF++ 6J3UD$eD5 5 6 NMMMMM!$(899 
66.1.C.CDN.S.SO(.(G(GI8<I5#D$	::::( 6 6 6#D$555556'6 6sO     AA=<A=+AD88EE1BH??
I.	I))I.AM++N	N	r%   	predicater   )_method_namec                V    t          | j        |          }t          j        |g|R i |S r\   )r2   r   rJ   rx   )r#   r   r]   r_   async_methods        r$   sync_methodz;AsyncToSyncConverter.create_sync_class.<locals>.sync_methodD  sF    #*4+?#N#NL/C$'+  /5  r&   c                <    t          | j        |          } ||i |S r\   )r2   r   )r#   r   r]   r_   methods        r$   proxy_methodz<AsyncToSyncConverter.create_sync_class.<locals>.proxy_methodO  s)    $T%9<HHF!6426222r&   c                 ,    t          | t                    S r\   r   propertyxs    r$   <lambda>z8AsyncToSyncConverter.create_sync_class.<locals>.<lambda>Y  s    :a#:#: r&   c                 J      fd} fd}t          ||j        r|nd           S )Nc                 j    t          | j                  t          j                  rfd}|S S )Nc                  .    t          j        g| R i |S r\   )rJ   rx   )r]   r_   values     r$   sync_fnz^AsyncToSyncConverter.create_sync_class.<locals>.make_property.<locals>.getter.<locals>.sync_fna  s5    #7#K %$(,$ $ $06$ $ r&   )r2   r   r   iscoroutinefunction)r#   r   r   r   s     @r$   getterzMAsyncToSyncConverter.create_sync_class.<locals>.make_property.<locals>.getter]  sN    #D$8$??E2599 '    
  ' Lr&   c                 4    t          | j        |           d S r\   )r   r   )r#   r   r   s     r$   setterzMAsyncToSyncConverter.create_sync_class.<locals>.make_property.<locals>.setteri  s    D0$>>>>>r&   )r   fset)r   prop_objr   r   s   `   r$   make_propertyz=AsyncToSyncConverter.create_sync_class.<locals>.make_property\  sR    
! 
! 
! 
! 
!? ? ? ? ?  (-(ITJJJr&   )rV   rG   r)   r   r   
isfunctionr   r   	functoolswrapsr   r   )rU   rz   thread_pool_sizesync_class_namesync_class_dictr%   r   r   r   r   propr   
sync_classs   ``           r$   r   z&AsyncToSyncConverter.create_sync_class   s    -,--- #*%0+)	
 
[	6 [	6 [	6 [	6 [	6 [	6z '/
# $.7#5
 
 
 	5 	5LD& s##  *622 5((:>     )( )4%% ((;? 3 3 3 3 )(3
 )5%% ",::
 
 	> 	>JD$K K K$ %2M$$=$=OD!! /F9oFF
r&   type_trackerc                    |t           j        j        u s|t           j        j        u rdS |t	          d          u rdS |r|                    |           	 t          |          }t          |          }||r|                    |           t          |dt          |                    }d|v r|
                    d          d         }t          |          dk    s|dk    rd	}|rbg }|D ]B}|r|                    |           |                    |                     ||                     C| d
d                    |           dS |S n# t          t          f$ r Y nw xY wt!          |d          rt!          |d          r|j        }t!          |d          r|j        n't          |          
                    d          d         }g }|j        D ]+}|                    |                     ||                     ,| d
d                    |           dS t!          |d          r|j        S t!          |d          rt!          |d          r|j        S t          |          }|                    d          r|                    d          r
|dd         }dD ].}	|                    |	          r|t/          |	          d         }/|dv rdS |dk    rdS |S )zFConvert a type annotation to its string representation for stub files.r   Nr   r(   .z<class 'types.UnionType'>r.   r   [r>   ]
__origin____args__'r;   r)   r*   z<class 'z'>   )ztyping.z	builtins.ztypes.)_emptyzinspect._emptyNoneType)r   	Parameterempty	Signaturer   r7   r   r   r2   r   splitrA   _format_type_annotationrC   AttributeError	TypeErrorr   r   r(   r   r*   r   endswithrB   )
rU   r3   r   originr]   origin_nameformatted_argsargtype_strprefixs
             r$   r   z,AsyncToSyncConverter._format_type_annotationu  s{    '+111W.4445 d##6  	0##J/// 	
++FJ''D! 4 ++F333 &fj#f++FF+%%"-"3"3C"8"8"<K v;;"===P[A[A[")K  	'%'N# ^ ^' 9(33C888&--c.I.I#|.\.\]]]])HHDIIn,E,EHHHH&&3 "4 	* 	 	 	D	
 :|,, 	7Z1P1P 	7*F 6:../[[&&s++A.  D!* L LC77\JJKKKK!66DIIdOO6666 :z** 	'&& :|,, 	+^1T1T 	+** z?? z** 	&x/@/@/F/F 	&"~H 9 	3 	3F""6** 3#CKKMM2 3336 z!!6s   C2E
 E
 
EEc                 p    t          |d          r%t          |j                  dk    r|j        d         S |S )z;Extract the actual return type from a Coroutine annotation.r      )r   rB   r   )rU   r3   s     r$   _extract_coroutine_return_typez3AsyncToSyncConverter._extract_coroutine_return_type  s?     :z** 	*s:3F/G/G!/K/K&q))r&   c                     |t           j        j        u rdS |dS t          |t                    rd| S |i k    rdS |g k    rdS d| S )z2Format a parameter's default value for stub files.r+   Nz = Nonez = z = {}z = [])r   r   r   r   r   )rU   default_values     r$   _format_parameter_defaultz.AsyncToSyncConverter._format_parameter_default  ss     G-3332"9t,, 	)((((b  7b  7((((r&   Tsig	skip_self
type_hintsc                    g }|i }t          |j                                                  D ]\  }\  }}|dk    r|dk    r|r|                    d           ,|                    ||j                  }	|                     |	|          }
|                     |j                  }|	t          j
        j        u r|                    | d|            |                    | d|
 |            d                    |          S )z(Format method parameters for stub files.Nr   r#   z: Anyr   r>   )	enumerate
parametersr@   rA   getr3   r   r   defaultr   r   r   rC   )rU   r   r   r   r   paramsi
param_nameparamr3   r   default_strs               r$   _format_method_parametersz.AsyncToSyncConverter._format_method_parameters  s&    J&/0D0D0F0F&G&G 	L 	L"A"
EAvv*..9.f%%%% (^^J8HII
66z<PP ";;EMJJ !2!888MMZ"C"Ck"C"CDDDDMMZ"J"J8"J["J"JKKKKyy   r&   method_nameis_asyncc                    t          j        |          }	 ddlm}  ||          }n# t          $ r i }Y nw xY w|                    d|j                  }|r)t          j        |          r|                     |          }| 	                    |||          }	| 
                    ||          }
|t           j        j        u rd}
d| d|	 d|
 d	S )
z4Generate a complete method signature for stub files.r   r   r9   r   r   r   def () -> : ...)r   	signaturer,   r   rg   r   return_annotationr   r   r   r   r   r   )rU   r   r   r   r   r   r   r   r   
params_strreturn_types              r$   _generate_method_signaturez/AsyncToSyncConverter._generate_method_signature  s    ''	------'//JJ 	 	 	JJJ	
 'NN8S5JKK 	V3F;; 	V # B BCT U U 223:\h2ii
 112C\RR 1 777 KGkGGJGG[GGGGs   ( 77c                    g }|                     d           |j        dk    rzt          j        |          }g }|rt	          |dd          }t          t          j        |                    D ]\  }}t          |t                    r|||vr
||j	        vr*t          |t                    r@t          |d          r0|                     |           |j                            |           t          |t                    r5|dk    r/|                     |           |j                            |           |r?d                    |j        g|z             }	|                     d|j         d	|	            n%|                     d|j         d	|j                    |                    |                    |j        
                     t          t          j        |          d          rkt          j        |          j        }
d|
v rN|
                    d          d         t+          fd|D                       s|                     d            |S )z-Generate import statements for the stub file.z[from typing import Any, Dict, List, Optional, Tuple, Union, Set, Sequence, cast, NamedTupler0   __all__N_fieldsr   r>   r<   r=   )r8   r(   r   r   c              3   H   K   | ]}|                     d            V  dS )r<   N)r   ).0impbase_modules     r$   	<genexpr>z9AsyncToSyncConverter._generate_imports.<locals>.<genexpr>q  s8      TTS3>>*?+*?*?@@TTTTTTr&   import )rA   r)   r   	getmoduler2   r?   r   r   r   r    r   r   r   r"   addr   rC   r(   extendrF   r   any)rU   rz   r   rD   r5   additional_types
module_allr   objtype_importsmodule_namer  s              @r$   _generate_importsz&AsyncToSyncConverter._generate_imports4  s   
  	i	
 	
 	

 !Z//&{33F! D$VY==
!'(:6(B(B!C!C D DID#!#t,, D &1d*6L6L#<+HHH ( &c511 Dgc96M6M D,33D999(9==dCCCC'T22 Dtv~~,33D999(9==dCCC #yy+*>)?BR)RSSU{'=UU|UUVVVVRK2RRK<PRR   	$$k6L$MM	
 	
 	

 7$[11:>> 	<!+K88AKk!!)//44Q7TTTTGTTTTT <NN#:[#:#:;;;r&   c                    g }	 t          |          }n# t          $ r i }Y nw xY wt          t          j        |                    D ]\  }}t          |t                    r-|                    d          s|                    ||f           G||v r4||         }t          |t                    r|                    ||f           |S )z5Extract class attributes that are classes themselves.r   )	r   rg   r?   r   r   r   r   r   rA   )rU   rz   class_attributesr   r   r   r3   s          r$   _get_class_attributesz*AsyncToSyncConverter._get_class_attributesv  s     	'44JJ 	 	 	JJJ	 !!3K!@!@AA 	@ 	@JD$$%% @dooc.B.B @ ''t5555##'-
j$// @$++T:,>???s    ##    r   r   indentc                    g }|                     | d| d           t          |d          r8|j        r1|                    |                     |j        | d                     t          |d          r	 t          |d          }t          j        |          }	 ddlm	}  ||          }	n# t          $ r i }	Y nw xY w|                     ||	|          }
t          |d          r8|j        r1|                    |                     |j        | d                     |                     | d	|
 d
           n/# t          t          f$ r |                     | d           Y nw xY wd}t          t          j        |t          j                            D ]\  }}|                    d          rd}	 |j        r1|                    |                     |j        | d                     |                     ||d|          }|                     | d|            # t          t          f$ r |                     | d| d           Y w xY w|s|                     | d           |S )z!Generate stub for an inner class.class zSync:rG   r  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)rA   r   rG   r
  _format_docstring_for_stubr2   r   r   r,   r   rg   r   
ValueErrorr   r?   r   r   r   r   )rU   r   r   r  r   
stub_linesinit_methodinit_sigr   
init_hintsr   has_methodsr   r   
method_sigs                  r$   _generate_inner_class_stubz/AsyncToSyncConverter._generate_inner_class_stub  sk    
V664666777 4## 	 	..t|___MM  
 4$$ 	%dJ77",[99$555555!/!<!<JJ  $ $ $!#JJJ$ !::, ;  
 ;	22 {7J %%66'/F   
 !!JJ
JJJ    	*   !!SSS     #)tw/ABBB$
 $
 	 	K %%c** K> %%66v~&WW   !;;$\ <  
 !!V"="="="=>>>>	*   !!PP{PPP    
  	3111222sJ   7$D< B. -D< .B=:D< <B==A>D< <)E('E(8A+H$$,II	docstringc                 x   |sg S t          j        |                                          }|                    d          }g }|                    | d           |D ]E}|                                r|                    | |            0|                    d           F|                    | d           |S )zHFormat a docstring for inclusion in a stub file with proper indentation.
z"""r+   )textwrapdedentstripr   rA   )rU   r(  r  dedentedlinesrX   lines          r$   r  z/AsyncToSyncConverter._format_docstring_for_stub  s    
  	I ?9--3355 t$$ nnn%%% 	" 	"Dzz|| "///0000b!!!!nnn%%%r&   stub_contentc                 d   g }|D ]}|                     d          r|                    |           -|                                                     d          rA|                                                    d          rd|vr|                    dd          }|                    |           |S )z6Post-process stub content to fix any remaining issues.)r<   r  r   r   r   z -> None: ...)r   rA   r-  r   replace)rU   r1  	processedr0  s       r$   _post_process_stub_contentz/AsyncToSyncConverter._post_process_stub_content  s     	  	# 	#D344   &&& 

''//>JJLL))'22> 4'' ||G_==T""""r&   r   c           	      n   	 |j         dk    rdS t          j        |          }|sdS |j        }|sdS t          j                            |          }t          j                            |d          }t	          j        |d           t          j        	                    |          }|
                    d          r
|dd         }t          j                            ||j         d          }t                      }	g }
t          |
          }|
                    d	           |
                    d
|j         d           |j        r.|
                    |                     |j        d                     	 |j        }t          j        |          }	 ddlm}  ||          }n# t,          $ r i }Y nw xY w|                     |||	          }t1          |d          r5|j        r.|
                    |                     |j        d                     |
                    d| d           n,# t2          t4          f$ r |
                    d           Y nw xY w|
                    d	           |                     |          }|D ]G\  }}|                     |||	          }|
                    |           |
                    d	           Ht;                      }t=          t          j        |t          j                             D ]\  }}|!                    d          s||v r|"                    |           	 | #                    ||d|	          }|j        r.|
                    |                     |j        d                     |
                    d|            |
                    d	           # t2          t4          f$ r1 |
                    d| d           |
                    d	           Y w xY wt=          t          j        |d                     D ]\  }}|
                    d           |
                    d| d           |j$        r2|
                    d| d           |
                    d| d           |
                    d	           i }	  ||          }n`# t,          $ rS i }tK          t          j&        |                    D ],}t1          |d           r|'                    |j(                   -Y nw xY wt=          |)                                          D ]N\  }}|D ]F\  }}||k    s6t1          |d!          r|j        |k    stU          |tV                    r||k    r|||<   GO|D ]7\  }}|,                    ||          }|
                    d| d"| d#           8|
                    d	           | -                    ||	          } t;                      }!g }"| D ]H}#|#|!vr+|!"                    |#           |"                    |#           1t]          j/        d$|#            I|"|
||d%z   <   | 0                    |
          }
tc          |d&          5 }$|$2                    d'                    |
                     ddd           n# 1 swxY w Y   t]          j3        d(|            dS # t,          $ ra}%t]          j4        d)|j         d"tW          |%                      ddl5}&t]          j4        |&6                                           Y d}%~%dS d}%~%ww xY w)*z_
        Generate a .pyi stub file for the sync class to help IDEs with type checking.
        r1   N	generatedT)exist_okz.pyz.pyir+   r  :r  r   r   r   rG   r  r  r  )r   r   r   r  r  r  c                 ,    t          | t                    S r\   r   r   s    r$   r   z9AsyncToSyncConverter.generate_stub_file.<locals>.<lambda>  s    *Q:Q:Q r&   z    @propertyz(self) -> Any: ...z    @z.setterz(self, value: Any) -> None: ...r   r(   r   SynczDuplicate import detected: r;   wr*  zGenerated stub file: zError generating stub file for )7r)   r   r  __file__ospathdirnamerC   makedirsbasenamer   r(   r	   rB   rA   rG   r
  r  r%   r   r,   r   rg   r   r   r   r   r  r'  r   r?   r   r   r   r	  r   r   r   r   r   r   r@   r   r   r   r  r   r   r5  openwriteinfoerror	traceback
format_exc)'rU   rz   r   r5   module_path
module_dirstub_dirr  sync_stub_pathr   r1  imports_placeholder_indexr"  init_signaturer   r$  r   r  r   r   inner_class_stubprocessed_methodsr   r&  r   attribute_mappingsr   r   r   r   
class_name
class_typerD   seenunique_importsr  frm   rH  s'                                          r$   generate_stub_filez'AsyncToSyncConverter.generate_stub_file  s	   
G	2%33&{33F  /K  55Jw||J<<H K40000'**;77K##E** /)#2#.W\\(z7J4P4P4PQQN '==LL ),L(9(9%###  ?)< ? ? ?@@@ " ##22;3FOO  
)2!(!2;!?!?$555555!/!<!<JJ  $ $ $!#JJJ$ !::"z ;  
 ;	22 {7J  ''66{7JFSS   ##$R
$R$R$RSSSS	*   ##J    
 ###  #88EE / ( (
d#&#A#A$\ $B $ $  ##$4555##B'''' !$ &";':LMMM! ! , ,f ??3'' 43D+D+D!%%d+++,!$!?!?ft, "@ " "J
 ~ $++::6>6RR   !''(;z(;(;<<< ''++++"I. , , , ''(U4(U(U(UVVV ''+++++, %";0Q0QRR  
( 
(
d ##O444##$Gt$G$G$GHHH9  ''(=(=(=(=>>> ''H4HHH   ##B'''' "$K"0."="= K K K"$"*7>++F+F"G"G K KJz+<== K'..z/IJJJK KK )//D/D/F/F(G(G C C$	9.> C C*J
 "Z//#Iz:: 0?H?QU_?_?_&y#66 @`;D
;R;R9B*:6C +; J J&
J.22:zJJ	 ##$H9$H$H
$H$H$HIIII### ++KFFG 55DN I Id??HHSMMM"))#....O$G#$G$GHHHH  25NQR5RRS
 99,GGL nc** 1a		,//0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1 LAAABBBBB 	2 	2 	2MQ*2EQQQQQ   M)..00111111111	2s   [	 [	 	[	 E[	 5H, F# "H, #F2/H, 1F22A9H, +[	 ,&I[	 IC&[	 <A;N87[	 8?O:7[	 9O::B*[	 %R1 0[	 1AT[	 TE"[	 0)Z%[	 %Z))[	 ,Z)-[	 	
\4A\//\4r\   ry   )TNN)FN)r  N)r  )&r(   r)   r*   rG   rK   r   rR   rS   rT   r   	threadingLockrQ   rP   classmethodrV   rx   r   r   r	   r   r   r   r   r   r   r   r   r   r   r   r  r   r  r'  r  r5  rX  rH   r&   r$   rJ   rJ   e   s          EIL(:-@AHHH&	(($   *2D2W       [ & >* >* [>*@ o oD o$ o o o [ob ?Cb b'/'<b	b b b [bH   [ ) ) ) ) [)  %).2! !! ! TN	!
 {+! 
! ! ! [!> 
 .2H HH 	H
 {+H 
H H H [HB ??.9?	c? ? ? [?B    eCI>N9O       [ , 
 .2M MM M 	M
 {+M 
cM M M [M^ +1 %(	c   [4 d3i DI    [. K2T K2t K2 K2 K2 K2 [K2 K2 K2r&   rJ   ry   rz   r9   c                 8    t                               | |          S )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
    )rJ   r   )rz   r   s     r$   r   r     s      11+?OPPPr&   rY  )rb   concurrent.futuresrR   rs   r   r   r   r?  r+  rZ  enumr   r,   r   r   r   r   r	   rJ   r   r   rH   r&   r$   <module>r`     s4                  				            A A A A A A A A A A A AT T T T T T T Tnw2 w2 w2 w2 w2 w2 w2 w2tQ Q4 Q Q Q Q Q Q Qr&   