o
    qoi@y                  	   @   s  U d 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	Z	ddl
Z
ddlZddlZddl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 ddlmZ ddlmZ dd	lmZ d
Zdej fddZ!ej"ddG dd dej#Z$ej"ddG dd de$Z%ej"ddG dd de$Z&ej"ddG dd dej#Z'ej(ddZ)e)j*Z*e)j+Z+dd Z,dd Z-dee fddZ.e/e0fD ]Z1e*e1d d! e1fd"d!d#d! d$ qe*e2d%d! d&d! d'd! d$ e*ej3d(d! d)d! d*d! d$ d+d, Z4d-ej5d.e6fd/d0Z7d1eej5 d.ee6 fd2d3Z8G d4d5 d5e9Z:G d6d7 d7ej;d8Z<G d9d: d:e9Z=G d;d< d<e<Z>d=e6d>e6d.e6fd?d@Z?dAe<d=e6d>e6fdBdCZ@dDe6d.e6fdEdFZAej"G dGdH dHZBi ZCeeDeBf eEdI< i ZFeeeBf eEdJ< d=e6d>e6dKeGfdLdMZHdNeejI d.dfdOdPZJdQZKdRZLdSZMdTZNdUZOd1ZPdVZQdWZRdXZSdYZTdZZUd[ZVd\ZWd=ZXdDZYd]d^ ZZG d_d` d`Z[G dadb dbe9Z\G dcdd ddZ]		dldYedeee< dfeeD d.e6fdgdhZ^	dmdie6deee< d.efdjdkZ_dS )na(  Functions to help serialize configuration.

This module provides functions that help ensure pickle-compatibility
(`clear_argument_history`), as well as functions and associated helper classes
used to serialize Fiddle structures into a custom JSON-based representation
(`dump_json`, `load_json`).
    N)AnyDictIterableListOptionalType)daglish)config)reraised_exception)special_overrides)daglish_legacy)lazy_importsz0.0.1	buildablec                 C   s&   dt dtjdt fdd}tj|| S )a'  Creates a copy of a buildable, clearing its history.

  This can be useful when a Config's history contains a non-picklable value.

  Args:
    buildable: A Fiddle configuration DAG whose history will be removed.

  Returns:
    A copy of `buildable` with `__argument_history__` set to empty.
  valuestatereturnc                 S   sN   | | r"t| tjr|| }|j }|j|j	|S |
| S t| S N)is_traversable
isinstance
config_lib	Buildableflattened_map_childrenmetadatawithout_historynode_traverser	unflattenvaluesmap_childrencopydeepcopy)r   r   sub_resultsr    r!   Z/home/ubuntu/.local/lib/python3.10/site-packages/fiddle/_src/experimental/serialization.pytraverse>   s   





z(clear_argument_history.<locals>.traverse)r   r   StateMemoizedTraversalrun)r   r#   r!   r!   r"   clear_argument_history2   s   r'   T)frozenc                   @   s   e Zd ZdZdefddZdS )UnreachableElementzRepresents an unreachable element.

  These are added during the serialization traversal below to provide more
  informative error messages.
  	containerc                 C   s   t d)Nz'Unreachable elements can't be followed.)NotImplementedErrorselfr*   r!   r!   r"   followT   s   zUnreachableElement.followN)__name__
__module____qualname____doc__r   r.   r!   r!   r!   r"   r)   L   s    r)   c                   @      e Zd ZdZedd ZdS )
SetElementzRepresents an element of a set.c                 C      dS )Nz[<set element>]r!   r-   r!   r!   r"   code\      zSetElement.codeNr/   r0   r1   r2   propertyr7   r!   r!   r!   r"   r4   X       r4   c                   @   r3   )MetadataElementz-Represents traversal into a value's metadata.c                 C   r5   )Nz.<metadata>r!   r6   r!   r!   r"   r7   e   r8   zMetadataElement.codeNr9   r!   r!   r!   r"   r<   a   r;   r<   c                   @   s*   e Zd ZdZedd ZdefddZdS )IdentityElementz0Represents a path element that is its container.c                 C   r5   )N r!   r6   r!   r!   r"   r7   n   r8   zIdentityElement.coder*   c                 C   s   |S r   r!   r,   r!   r!   r"   r.   r      zIdentityElement.followN)r/   r0   r1   r2   r:   r7   r   r.   r!   r!   r!   r"   r=   j   s
    
r=   )use_fallbackc                 C   s$   t | j }| j t| |ffS r   )tuple__dict__keysr   type)instancerC   r!   r!   r"   _flatten_standard_object~   s   rF   c                 C   s(   |\}}t |}|jt||  |S r   )object__new__rB   updatezip)r   r   object_type	dict_keysrE   r!   r!   r"   _unflatten_standard_object   s   
rM   rK   c                 C   s   t | ttdd d dS )aN  Registers serialization support for the given (dict-based) `object_type`.

  This adds serialization support for "dict-based" Python objects, where here
  dict-based means that we can simply serialize the `object_type.__dict__`
  attribute, and on deserialization create a new empty instance of `object_type`
  and restore its `__dict__` contents. If this behavior is insufficient or
  incorrect for a given type, more explicit handling using
  `register_node_traverser` will be required to support serialization.

  Args:
    object_type: The type to register serialization support for.
  c                 S   s   t dd | jD S )Nc                 s   s    | ]}t |V  qd S r   )r   Attr).0kr!   r!   r"   	<genexpr>   s    z?register_dict_based_object.<locals>.<lambda>.<locals>.<genexpr>)rA   rB   xr!   r!   r"   <lambda>       z,register_dict_based_object.<locals>.<lambda>
flatten_fnunflatten_fnpath_elements_fnN)register_node_traverserrF   rM   )rK   r!   r!   r"   register_dict_based_object   s   
r[   c                 C   s   t | d fS r   rA   rR   r!   r!   r"   rT      s    rT   c                 C   s   || S r   r!   )r   _set_typer!   r!   r"   rT          c                 C   s   t dd | D S )Nc                 s   s    | ]}t  V  qd S r   )r4   )rO   r]   r!   r!   r"   rQ      s    z<lambda>.<locals>.<genexpr>r\   rR   r!   r!   r"   rT      s    rV   c                 C   s   |  dfd fS )Nraw_unicode_escape)decoderR   r!   r!   r"   rT      s    c                 C   s   | d  dS )Nr   r`   )encode)r   r]   r!   r!   r"   rT      s    c                 C   s   t  fS r   )r=   rR   r!   r!   r"   rT      r_   c                 C   r5   )N)r!   Nr!   r]   r!   r!   r"   rT          c                 C   s   t jS r   )r   NO_VALUE)r   r   r!   r!   r"   rT      s    c                 C   r5   )Nr!   r!   rc   r!   r!   r"   rT      rd   c                 C   s   | t ttttdfv S )zDReturns whether `value_type` is a JSON-representable primitive type.N)intfloatboolstrrD   )
value_typer!   r!   r"   _is_leaf_type   s   rk   pathr   c                 C   s   dt |  S )z!Returns a path string for `path`.z<root>)r   path_str)rl   r!   r!   r"   rm         rm   pathsc                 C   s   dd | D S )z8Returns a list of path strings corresponding to `paths`.c                 S   s   g | ]}t |qS r!   )rm   )rO   rl   r!   r!   r"   
<listcomp>   rU   zpath_strs.<locals>.<listcomp>r!   )ro   r!   r!   r"   	path_strs   rn   rq   c                   @      e Zd ZdZdS )UnserializableValueErrorz@An exception thrown when an unserializable value is encountered.Nr/   r0   r1   r2   r!   r!   r!   r"   rs      s    rs   c                   @   s>   e Zd ZdZejdededefddZde	defdd	Z
d
S )PyrefPolicyzRepresents a policy for importing references to Python objects.

  A `PyrefPolicy` provides control over what kind of Python symbols can be
  loaded during deserialization.
  modulesymbolr   c                 C   r5   )aH  Returns whether this policy allows importing `symbol` from `module`.

    This will be called by `import_symbol` before any imports take place. If
    this returns `True`, `symbol` will be imported from `module`.

    Args:
      module: The module to import `symbol` from.
      symbol: The symbol to import from `module`.
    Nr!   r-   rv   rw   r!   r!   r"   allows_import   rd   zPyrefPolicy.allows_importr   c                 C   r5   )zReturns whether this policy allows an imported `value` to be used.

    This is called after `value` has already been imported, but before it is
    returned by `import_symbol`.

    Args:
      value: An imported value.
    Nr!   r-   r   r!   r!   r"   allows_value   rd   zPyrefPolicy.allows_valueN)r/   r0   r1   r2   abcabstractmethodri   rh   ry   r   r{   r!   r!   r!   r"   ru      s
    ru   )	metaclassc                       s8   e Zd ZdZe Zdedededef fddZ	  Z
S )PyrefPolicyErrorzAAn error arising when an import is disallowed by a `PyrefPolicy`.policyrv   rw   r   c                    sZ   || _ || _|| _|tjurd|d}nd}d| d| | d| d}t | d S )Nz (with value )r>   z
Importing  from z9 is not permitted by the active Python reference policy (z).)rv   rw   r   r   
PRE_IMPORTsuper__init__)r-   r   rv   rw   r   	value_strmsg	__class__r!   r"   r      s   
zPyrefPolicyError.__init__)r/   r0   r1   r2   rG   r   ru   ri   r   r   __classcell__r!   r!   r   r"   r      s    &r   c                   @   s&   e Zd ZdZdd ZdefddZdS )DefaultPyrefPolicya   Provides a default policy for loading pyref values.

  This policy excludes builtins that are not a supported serializable type
  (e.g., `list`, `tuple`, `dict`, etc are allowed). This policy is subject to
  change and may become stricter in the future.
  c                 C   r5   )NTr!   rx   r!   r!   r"   ry      r?   z DefaultPyrefPolicy.allows_importr   c                 C   s<   t |to
t|d u}tt|dd }|tjv }|p| S )Nr/   )r   rD   find_node_traversergetattrinspect	getmodulesysbuiltin_module_names)r-   r   is_serializable_typemodule_name
is_builtinr!   r!   r"   r{     s
   

zDefaultPyrefPolicy.allows_valueN)r/   r0   r1   r2   ry   rh   r{   r!   r!   r!   r"   r      s    r   rv   rw   c                 C   s   d|d| dS )Nz9
Fiddle context: Error occurred while importing pyref to r   .r!   )rv   rw   r!   r!   r"   _fiddle_pyref_context  s   r   r   c                 C   s   t j}| ||rDt||}tt||}t	| t
|}|dD ]}t||}q&W d   n1 s8w   Y  | |rD|S t | |||)a  Returns the value obtained from importing `symbol` from `module`.

  Args:
    policy: The `PyrefPolicy` governing which symbols can be imported.
    module: The module to import `symbol` from.
    symbol: The symbol to import from `module`.

  Raises:
    ModuleNotFoundError: If `module` can't be found.
    AttributeError: If `symbol` can't be accessed on `module`.
    PyrefPolicyError: If importing `symbol` from `module` is disallowed by
      this `PyrefPolicy`.
  r   N)r   r   ry   r   ;maybe_get_module_override_for_migrated_serialization_symbol	functoolspartialr   r
   try_with_lazy_message	importlibimport_modulesplitr   r{   )r   rv   rw   r   make_message	attr_namer!   r!   r"   import_symbol  s   

r   namec                 C   s   t dd|  S )z:Converts a camel or studly-caps name to a snake_case name.z(?<=[^_A-Z])(?=[A-Z])r]   )resublower)r   r!   r!   r"   _to_snake_case0  s   r   c                   @   s&   e Zd ZU eed< eed< dd ZdS )SerializationConstantrv   rw   c                 C   s   t tt| jt| jiS r   )	_TYPE_KEY_PYREF_TYPE_MODULE_KEYrv   	_NAME_KEYrw   r6   r!   r!   r"   to_pyref:  s   zSerializationConstant.to_pyrefN)r/   r0   r1   ri   __annotations__r   r!   r!   r!   r"   r   5  s   
 r   _serialization_constants_by_id!_serialization_constants_by_valuecompare_by_identityc                 C   s   t t | |}t|ttjfrtd|  d| dtt|r+td|  d| dtt|dur>td|  d| dt	| |}|rM|t
t|< dS |t|< dS )a   Registers a module-level constant value for serialization.

  The specified value will be serialized as a pyref (python reference), meaning
  that its value will be deserialized by reading the specified symbol from the
  specified module.

  Args:
    module: The name of the module containing the constant symbol.
    symbol: The symbol in `module` that contains a constant value.
    compare_by_identity: If True, then only use a pyref to serialize a value `x`
      if `x is <module>.<symbol>`.  If False, then use a pyref to serialize any
      value `x` where `x == <module>.<symbol>`.  If `compare_by_identity` is
      False, then the value must be hashable.

  Raises:
    ModuleNotFoundError: If `module` can't be found.
    AttributeError If 'symbol' can't be accessed on `module`.
    PyrefPolicyError: If importing `symbol` from `module` is disallowed by the
      `DefaultPyrefPolicy`.
    ValueError: If registration is unnecessary for `<module>.<symbol>` (e.g.,
      because it is a `type` or `function`).
  zCan not register r   z_ as a serialization constant because it is a type or function (so registration is unnecessary).zp as a serialization constant because it is a JSON-representable primitive type (so registration is unnecessary).Nzg as a serialization constant because it is a daglish-traversable type (so registration is unnecessary).)r   r   r   rD   typesFunctionType
ValueErrorrk   r   r   r   idr   )rv   rw   r   r   serialization_constantr!   r!   r"   register_constantF  s"   
r   	enum_typec                 C   s,   | j D ]}t| j| j d| dd qdS )zRegisters all members of the given enum using `register_constant`.

  Args:
    enum_type: Any class that inherits from `enum.Enum`.
  r   T)r   N)__members__r   r0   r1   )r   r   r!   r!   r"   register_enumw  s   
r   rootobjects	refcountsversionrD   itemsr   leafr   refkeypyrefc                 C   sj   | j }|d}t|dkr|\}}nt|dkr#|jddd\}}ntd| dttt|t|i}|S )z(Serialize proxy object for lazy imports.:      r   )maxsplitzInvalid qualname z for ProxyObject.)	r1   r   lenrsplitr   r   r   r   r   )proxy_objectqualnamepartsr   symbol_nameoutputr!   r!   r"   _serialize_lazy_imports  s   

r   c                   @   s   e Zd ZdZ	ddedee fddZede	e
ef fdd	Zdede
fd
dZdd ZdejfddZdd Z	ddedejdeej de	e
ef fddZdS )Serializationa]	  Maintains state for an in-progress serialization.

  This class is used to recursively assemble a JSON-serializable dictionary
  representation of a given value. This class manages the state maintained
  during this process. The resulting dictionary representation can be obtained
  from the result property once an instance has been created:

      dict_representation = Serialization(value, pyref_policy).result

  A new instance of the class should be created per serialization.

  The resulting dictionary representation has the following keys at the
  top-level:

    * 'root': A dictionary representation of the root object.
    * 'objects': A dictionary mapping object names to their dictionary
        representations.
    * 'refcounts': A dictionary mapping object names to the number of times they
        are referenced (e.g., via other objects).
    * 'version': A version string, indicating what version of the serialization
        format produced this result.

  Individual object representations (as contained in 'root' and 'objects') may
  either be a JSON primitive value or a dictionary representation. Dictionary
  representations will always have a 'type' key, and additional fields which
  depend on this type:

    * Traversable structures (those that have either a serialization-specific
      or daglish traverser available) will have their type information,
      flattened items, and traversal metadata recursively serialized into a
      dictionary with keys 'type', 'items', and 'metadata'. The items will be
      a list of lists, where each sublist contains both a string representation
      of the item's `daglish.PathElement` (only used for debugging/visualization
      purposes) as well as the serialized item itself.
    * Python types and functions are serialized with a special 'pyref' type
      value, along with fields 'module' and 'name' that are used when importing
      the type or function during deserialization.
    * References to other objects have a special 'ref' type, and a 'key' field
      that identifies an object in the top-level 'objects' dictionary.
    * Leaf values that need path information will have a 'leaf' type, with an
      additional 'value' field that is always a JSON primitive value.

  Any object's dictionary representation may also have a 'paths' field that
  stores a list of all paths to that object from the root.
  Nr   pyref_policyc                 C   sl   i | _ i | _g | _tt| _|| _tj	|dd| _
|pt | _t| j| jdddt| jt| jtti| _dS )aY  Initializes the serialization.

    Args:
      value: The value to serialize.
      pyref_policy: The `PyrefPolicy` instance that should govern whether a
        given Python reference is permissible. Providing a policy here can help
        catch potential errors early, however this will only guarantee
        successful deserialization if the same policy is passed when creating a
        `Deserialization` instance.

    Raises:
      UnserializableValueError: If an unserializable value is encountered.
      ModuleNotFoundError: If a module can't be imported in the course of
        creating a Python reference.
      AttributeError: If an attribute or symbol can't be accessed in the course
        of creating a Python reference.
      PyrefPolicyError: If a Python reference (e.g., function or type) is
        disallowed by `pyref_policy`.
    T)memoizable_onlyr!   )r!   	all_pathsN)_memo_objects_ref_valuescollectionsdefaultdictrf   
_refcounts_rootr   collect_paths_by_id_paths_by_idr   _pyref_policy	_ROOT_KEY
_serialize_OBJECTS_KEY_REFCOUNTS_KEY_VERSION_KEY_VERSION_result)r-   r   r   r!   r!   r"   r     s   
zSerialization.__init__r   c                 C      | j S )z>Returns the serialization result (JSON-compatible dictionary).r   r6   r!   r!   r"   result     zSerialization.resultc              
   C   s   zt |}t|tjrt|}t|tjr|j}n|j}W n t	y2   t
ddtt |}Y nw t|}tdD ]}| d| }|| jvrM |S q<|S )z2Creates a unique and informative name for `value`.z[<>()\[\] '\"]r>   r   r]   )rD   r   r   r   get_callabler   ProxyObjectr   r/   AttributeErrorr   r   ri   r   	itertoolscountr   )r-   r   	hint_typehintir   r!   r!   r"   _unique_name  s&   

zSerialization._unique_namec                 C   s   | j |  d7  < ttt|iS )z1Creates a reference to another serialized object.r   )r   r   	_REF_TYPE_KEY_KEY)r-   r   r!   r!   r"   _ref/  s   zSerialization._refcurrent_pathc              	   C   s   t |}|du rd|d}t||j}t|tjr&|jjd |j	 }n|j}|t
| j||urGd|d|d|dt|d	}t|ttt|t|iS )	z2Creates a reference to an importable Python value.NzCouldn't find the module for z5; Are you wrapping the function or using a test mock?r   zCouldn't create a pyref for z/; the same value was not obtained by importing r   . Error occurred at path )r   r   rs   r/   r   enumEnumr   r1   r   r   r   rm   r   r   r   r   )r-   r   r   rv   r   r   rw   r!   r!   r"   _pyref4  s.   

zSerialization._pyrefc                 C   s   t tt|iS )zCreates a leaf value.r   
_LEAF_TYPE
_VALUE_KEYrz   r!   r!   r"   _leafP  s   zSerialization._leafr   c                 C   s^  t || jv r| | jt | S |dur| jt ||}tt|}|du rtt|r:|du r4|S | |}nt	|tt
jtjfrK| ||}nt	|tjrVt|}nt |tv rett |  }nt	|tjjrw|tv rwt|  }n{d| dt| dt|d}t|||\}}||}	t|t|	ksJ g }
t|	|D ]%\}}|durt||nd}| j |||f |d}||f}|
!| qt	|t"j#r|$ }| j ||t% f dd}t&| t||t'|
t(|i}|durt)||t*< t+|r-|t& t,kr-| -|}|| j.vsJ || jt |< || j.|< | j/!| | |S |S )aA  Returns a JSON-serializable dict representation of `value`.

    This function traverses `value`, recursively building up a JSON-serializable
    dictionary capturing values and associated metadata, debugging, and
    visualization info.

    Args:
      value: The value to serialize.
      current_path: The traversal's current path.
      all_paths: An optional list of all paths that reach `value`. If `None`, no
        path information will be added to `value`'s representation.

    Raises:
      UnserializableValueError: If an unserializable value is encountered.
    NzUnserializable value z	 of type r   z.")r   )0r   r   r   r   getr   rD   rk   r   r   r   r   r   r   r   r   r   r   r   r   r   r|   Hashabler   rm   rs   flattenpath_elementsr   rJ   r   add_path_elementr   appendr   BuildableTraverserMetadatar   r<   r   
_ITEMS_KEY_METADATA_KEYrq   
_PATHS_KEYis_memoizabler   r   r   r   )r-   r   r   r   	traverserr   r   r   r   r   serialized_itemspath_elementchild_valuechild_pathsserialized_valueserialized_itemserialized_metadatar   r!   r!   r"   r   W  sp   





zSerialization._serializer   )r/   r0   r1   r2   r   r   ru   r   r:   r   ri   r   r   r   r   Pathr   r   Pathsr   r!   r!   r!   r"   r     s0    1
0
r   c                   @   rr   )DeserializationErrorz7Represents an error that occurs during deserialization.Nrt   r!   r!   r!   r"   r    s    r  c                   @   sj   e Zd ZdZ	ddeeef dee fddZ	e
defdd	Zd
d Zdd Zdd ZdefddZdS )Deserializationa  Maintains state for an in-progress deserialization.

  This class is used to recursively recreate a Python object from its
  JSON-serializable dictionary representation (as created by the `Serialization`
  class above). This class manages the state maintained during this proces. The
  resulting deserialized value can be obtained from the result() method once an
  instance has been created:

      value = Deserialization(dict_representation, pyref_policy).result

  A new instance of the class should be created per deserialization.
  Nr  r   c                 C   s8   |t  | _i | _|t | _|pt | _| | j| _dS )aA  Initializes the deserialization.

    Args:
      serialized_value: The dictionary representation of the value to
        deserialize.
      pyref_policy: The `PyrefPolicy` instance that should govern whether a
        given Python reference is permissible. Defaults to `DefaultPyrefPolicy`
        if not specified.
    N)	r   _serialized_objects_deserialized_objectsr   r   r   r   _deserializer   )r-   r  r   r!   r!   r"   r     s
   

zDeserialization.__init__r   c                 C   r   )z*Returns the result of the deserialization.r   r6   r!   r!   r"   r     r   zDeserialization.resultc                 C   sJ   |t  tksJ |t }|| jv r| j| S | | j| }|| j|< |S r   )r   r   r   r  r  r  )r-   r   r   deserialized_objectr!   r!   r"   _deserialize_ref  s   


z Deserialization._deserialize_refc                 C   s&   |t  tksJ t| j|t |t S r   )r   r   r   r   r   r   )r-   r   r!   r!   r"   _deserialize_pyref  s   z"Deserialization._deserialize_pyrefc                 C   s   |t  tksJ |t S r   r   )r-   r   r!   r!   r"   _deserialize_leaf  s   z!Deserialization._deserialize_leafserialized_objectc                    s   t |tr fdd|D S t |ts|S |t }|tkr" |S |tkr+ |S |tkr4 	|S t |tr@|
ttkrHtd| d |}t|}|du r]td| d|t }dd  |D } |t }|||S )z7Recursively deserializes the given `serialized_object`.c                    s   g | ]}  |qS r!   )r  )rO   rS   r6   r!   r"   rp     s    z0Deserialization._deserialize.<locals>.<listcomp>zInvalid object type: r   Nz'No traverser available for object type c                 S   s   g | ]\}}|qS r!   r!   )rO   r]   r   r!   r!   r"   rp     rU   )r   listdictr   r   r  r   r  r   r  r   r  r  r   r  r  r   )r-   r  rK   r  r	  r   r   r!   r6   r"   r    s0   







zDeserialization._deserializer   )r/   r0   r1   r2   r   ri   r   r   ru   r   r:   r   r  r  r  r  r!   r!   r!   r"   r    s    


r  r   indentc                 C   s   t jt| |j|dS )a  Returns the JSON serialization of `value`.

  Args:
    value: The value to serialize.
    pyref_policy: A `PyrefPolicy` instance that governs which Python references
      are permissible. Providing a policy here can help catch potential errors
      early, however this will only guarantee successful deserialization if the
      same policy is passed when calling `load_json`. Defaults to
      `DefaultPyrefPolicy`.
    indent: An optional indentation to use when formatting the JSON. If given,
      the resulting JSON will be formatted with each new indentation level
      indented by `indent` spaces from the last for readability. If not
      provided, the resulting JSON will be compact with minimal whitespace.

  Raises:
    UnserializableValueError: If an unserializable value is encountered.
    PyrefPolicyError: If a Python reference (e.g., function or type) is
      disallowed by `pyref_policy`.
  )r  )jsondumpsr   r   )r   r   r  r!   r!   r"   	dump_json"  s   r!  r  c                 C   s   t t| |jS )a  Returns a Python object deserialized from `serialized_value`.

  Args:
    serialized_value: A JSON-serialized value.
    pyref_policy: A `PyrefPolicy` instance that governs which Python references
      are permissible.

  Raises:
    DeserializationError: If an unknown type or other serialization format error
      is encountered  during deserialization.
    ModuleNotFoundError: If a referenced module can't be imported.
    AttributeError: If a referenced attribute or symbol can't be accessed.
    PyrefPolicyError: If a Python reference (e.g., function or type) is
      disallowed by `pyref_policy`.
    json.decoder.JSONDecodeError: If Python's `json.loads` encounters an error
      while decoding the provided JSON.
  )r  r  loadsr   )r  r   r!   r!   r"   	load_json=  s   r#  )NNr   )`r2   r|   r   r   dataclassesr   r   r   r   r   r  r   r   r   typingr   r   r   r   r   r   fiddler   fiddle._srcr	   r   r
   r   fiddle._src.experimentalr   r   r   r   r'   	dataclassPathElementr)   r4   r<   r=   NodeTraverserRegistry_traverser_registryrZ   r   rF   rM   r[   set	frozensetr^   bytesNoValuerk   r  ri   rm   rq   	Exceptionrs   ABCMetaru   r   r   r   r   r   r   r   rf   r   r   rh   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!   r!   r!   r"   <module>   s    




1  i
