o
    ,wik	                     @   s>   d Z ddlmZ ddlmZ ddlmZ deddfdd	ZdS )
a  The materialize module makes implicit defaults explicit.

Fiddle Buildable's allow accessing argument defaults, but they are treated
differently by the systems compared to values that have been explicitly set
(e.g. by a user's configuration). (This enables users and tooling to quickly see
what has been configured explicitly.)

For when a configuration is to be persisted for longer-term archival,
materializing the defaulted values can make the configuration archive somewhat
more hermetic.
    )Any)config)daglishvaluereturnNc                 C   s"   dt jfdd}t j||  dS )a  Explicitly sets values for defaulted arguments.

  Buildable makes a distinction between a defaulted argument that hasn't been
  set, and an argument that has been explicitly set to a value (that may or may
  not be the same as the argument's default value).

  However, there are some instances where it can be valuable to explicitly
  materialize the defaulted values (e.g. when persisting a configuration in a
  text format, or for certain visualizations).

  Calling `materialize_defaults` on a Buildable is the equivalent of doing
  `cfg.MY_ARG = cfg.MY_ARG` for all arguments with default values that have not
  yet had a value explicitly set.

  Args:
    value: A nested collection which may contain Buildable arguments.
  statec                 S   s^   t | tjr#| jj D ]}|j|jur"|j| j	vr"t
| |j|j q|j| ddD ]}q*d S )NT)ignore_leaves)
isinstancer   	Buildable__signature_info__
parametersvaluesdefaultemptyname__arguments__setattryield_map_child_values)noder   arg_ r   T/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/fiddle/_src/materialize.pytraverse5   s   z&materialize_defaults.<locals>.traverseN)r   StateMemoizedTraversalrun)r   r   r   r   r   materialize_defaults"   s   r   )__doc__typingr   fiddle._srcr   r   r   r   r   r   r   <module>   s
   