o
    i                     @   s   U d Z ddlZddlZddlmZ i aejejeef ej	f e
d< ejaG dd deZdd Zd	d
 Zejdd Zdej	fddZdS )a  Utility for monkey patching typing.overload to allow run time retrieval overloads

Requires any @typing.overload to happen within the patched_overload contextmanager, e.g.:

```python
with patched_overload():
    # the following could be imported from some other module (as long as it wasn't already loaded), or inlined:

    @typing.overload
    def foo(a: int) -> float:
        ...

    def foo(a: typing.Union[bool, int]) -> typing.Union[bool, float]:
        if isinstance(a, bool):
            return a
        return float(a)

# returns reference to the overloads of foo (the int -> float one in this case)
# in the order they are declared
foo_overloads = get_overloads(foo)
    N)mock	overloadsc                   @   s   e Zd ZdS )UntrackableN)__name__
__module____qualname__ r   r   S/home/ubuntu/.local/lib/python3.10/site-packages/synchronicity/overload_tracking.pyr      s    r   c                 C   s<   t | ttfrt| jS z| j| jfW S  ty   t w N)	
isinstancestaticmethodclassmethod_function_locator__func__r   r   AttributeErrorr   fr   r   r	   r   #   s   
r   c                 C   sL   zt | }t|g |  W t| S  ty%   td|   Y t| S w )Nz#WARNING: can't track overloads for )r   r   
setdefaultappendr   printoriginal_overload)r   locatorr   r   r	   _tracking_overload-   s   r   c                   c   s:    t dt d V  W d    d S 1 sw   Y  d S )Nztyping.overload)r   patchr   r   r   r   r	   patched_overload9   s   "r   returnc                 C   s*   z	t t| g W S  ty   g  Y S w r
   )r   getr   r   r   r   r   r	   get_overloads?   s
   r   )__doc__
contextlibtypingunittestr   r   DictTuplestrList__annotations__overloadr   	Exceptionr   r   r   contextmanagerr   r   r   r   r   r	   <module>   s    "

