Ë
    †Kàis  ã                  ó¨   — d Z ddlmZ ddlmZ ddlmZmZmZ ddl	m
Z
mZmZ ddlmZ ddlmZmZ dd	lmZ  ed
«      Ze
Z G d„ dee   «      Zdd„Zy)z,Functional dependencies: Depends and Shared.é    )Úannotations)ÚCallable)ÚAnyÚTypeVarÚcast)ÚDependencyFactoryÚSharedÚSharedContext)Ú_Depends)Ú_parameter_cacheÚget_dependency_parametersé   )Ú_TaskArgumentÚRc                  ó    — e Zd ZdZ	 	 	 	 dd„Zy)r   z<Docket's call-scoped dependency with TaskArgument inference.c              ƒ  ó  K  — | j                   j                  «       }i }t        |«      }|j                  «       D ]D  \  }}t	        |t
        «      r|j                  s||_        |j                  |«      ƒ d {  –—† ||<   ŒF |S 7 Œ­w)N)ÚstackÚgetr   ÚitemsÚ
isinstancer   Ú	parameterÚenter_async_context)ÚselfÚfunctionr   Ú	argumentsÚ
parametersr   Ú
dependencys          úk/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/docket/dependencies/_functional.pyÚ_resolve_parametersz_Depends._resolve_parameters"   s†   è ø€ ð —
‘
—‘Ó ˆØ$&ˆ	Ü.¨xÓ8ˆ
à%/×%5Ñ%5Ó%7ò 	OÑ!ˆIzÜ˜*¤mÔ4¸Z×=QÒ=QØ'0
Ô$à).×)BÑ)BÀ:Ó)N×#NˆIiÒ ð		Oð Ðð $Oús   ‚A5BÁ7BÁ8BN)r   zCallable[..., Any]Úreturnzdict[str, Any])Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   © ó    r   r   r      s   „ ÙFðà$ðð 
ôr&   r   c                ó4   — t        t        t        | «      «      S )a,  Include a user-defined function as a dependency.  Dependencies may be:
    - Synchronous functions returning a value
    - Asynchronous functions returning a value (awaitable)
    - Synchronous context managers (using @contextmanager)
    - Asynchronous context managers (using @asynccontextmanager)

    If a dependency returns a context manager, it will be entered and exited around
    the task, giving an opportunity to control the lifetime of a resource.

    **Important**: Synchronous dependencies should NOT include blocking I/O operations
    (file access, network calls, database queries, etc.). Use async dependencies for
    any I/O. Sync dependencies are best for:
    - Pure computations
    - In-memory data structure access
    - Configuration lookups from memory
    - Non-blocking transformations

    Examples:

    ```python
    # Sync dependency - pure computation, no I/O
    def get_config() -> dict:
        # Access in-memory config, no I/O
        return {"api_url": "https://api.example.com", "timeout": 30}

    # Sync dependency - compute value from arguments
    def build_query_params(
        user_id: int = TaskArgument(),
        config: dict = Depends(get_config)
    ) -> dict:
        # Pure computation, no I/O
        return {"user_id": user_id, "timeout": config["timeout"]}

    # Async dependency - I/O operations
    async def get_user(user_id: int = TaskArgument()) -> User:
        # Network I/O - must be async
        return await fetch_user_from_api(user_id)

    # Async context manager - I/O resource management
    from contextlib import asynccontextmanager

    @asynccontextmanager
    async def get_db_connection():
        # I/O operations - must be async
        conn = await db.connect()
        try:
            yield conn
        finally:
            await conn.close()

    @task
    async def my_task(
        params: dict = Depends(build_query_params),
        user: User = Depends(get_user),
        db: Connection = Depends(get_db_connection),
    ) -> None:
        await db.execute("UPDATE users SET ...", params)
    ```
    )r   r   r   )r   s    r   ÚDependsr(   3   s   € ôx ””8˜JÓ'Ó(Ð(r&   N)r   zDependencyFactory[R]r    r   )r$   Ú
__future__r   Úcollections.abcr   Útypingr   r   r   Úuncalled_forr   r	   r
   Úuncalled_for.functionalr   Ú_UncalledForDependsÚuncalled_for.introspectionr   r   Ú_contextualr   r   ÚDependencyFunctionr(   r%   r&   r   ú<module>r2      sT   ðÙ 2å "å $ß %Ñ %÷ñ õ
 D÷õ
 'áˆCƒL€à&Ð ôÐ" 1Ñ%ô ô(<)r&   