o
    ,wi                     @   s   d Z ddlmZmZmZmZmZmZ ddlm	Z	 ddl
mZ ddl
mZ edeejeej f dZded	efd
dZded	eeedef f fddZdS )z/Transformation functions for Fiddle buildables.    )AnyCallableIterableOptionalTypeVarUnion)daglish)config)partialAnyBuildable)bound	buildablereturnc                    s"   ddt tj f fdd  | S )aj  Uninterns tuples of literals in the given buildable.

  Tuples of literals are tuples containing immutable primitive values. Python
  normally interns (i.e. share the same instance) tuples of literals. Interned
  objects are those that were declared in separate code locations but share the
  same instance (due to Python's optimizations). This can create problems with
  the differ and visualizer. This function "uninterns" these tuples (i.e.
  creates separate instances for each tuple) to solve this issue.

  Args:
    buildable: Any Fiddle buildable.

  Returns:
    A new buildable with the tuples uninterned.
  Nstatec                    sB   |p
t jj | dd}tttu rt | rtt| } || S )NF)memoize_internables)r   MemoizedTraversalbegintypetupleis_internablelistmap_childrenvaluer   	transform _/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/fiddle/_src/experimental/transform.pyr   /   s   

z.unintern_tuples_of_literals.<locals>.transform)N)r   r   State)r   r   r   r   unintern_tuples_of_literals   s   	r   .c                 C   s   dt jfdd}t j|| S )a  Replaces unconfigured `fdl.Partial` with their underlying callables.

  Args:
    buildable: Any Fiddle buildable.

  Returns:
    A new `fdl.Buildable` with any `fdl.Partial` that does not have any new
    arguments passed in replaced with just the function or class wrapped by the
    `fdl.Partial`. This function will return a `Callable` if a `fdl.Partial`
    was passed in that does not have any new arguments.
  r   c                 S   s0   t | tju rtj| ddst| } || S )NF)include_equal_to_default)r   r
   Partialr	   ordered_argumentsget_callabler   r   r   r   r   r   I   s
   

z?replace_unconfigured_partials_with_callables.<locals>.transform)r   r   r   run)r   r   r   r   r   ,replace_unconfigured_partials_with_callables;   s   r%   N)__doc__typingr   r   r   r   r   r   fiddler   fiddle._srcr	   r
   	Buildabler   r   r%   r   r   r   r   <module>   s    