
    hX                        % S SK Jr  S SKJr  S SKJrJrJrJr  S SK	J
r
  SSKJr  SSKJrJrJrJr  SS	KJrJrJrJr  S
rS\S'   \\/\\\S
4   4   r\\/\\S
4   4   rSqS\S'   SS jr\S 5       r " S S5      rg
)    )annotations)contextmanager)AnyCallableClassVarUnion)DEFAULT_SENTINEL_SINGLETONS   )	_resolver   )PrimitiveConstructorSpecPrimitiveTypeInfoUnsupportedTypeAnnotationErrorapply_default_primitive_rules)InvalidDefaultInstanceErrorStructConstructorSpecStructTypeInfoapply_default_struct_rulesNzConstructorRegistry | Nonecurrent_registryFbool_check_default_instances_flagc                     [         $ )a  Check whether we should be strict about checking that default types and
instances match.

This is usually `False`; tyro attempts to be somewhat lenient when
inconsistent types are encounted. Strictness, however, is useful for
matching annotated subcommands to default values.
r        U/home/james-whalen/.local/lib/python3.13/site-packages/tyro/constructors/_registry.pycheck_default_instancesr   !   s
     )(r   c               #  8   #    [         n Sq  Sv   U q g! U q f = f7f)a  Context for whether we should be strict about checking that default
types and instances match.

This is usually `False`; tyro attempts to be somewhat lenient when
inconsistent types are encounted. Strictness, however, is useful for
matching annotated subcommands to default values.
TNr   )	old_values    r   check_default_instances_contextr    ,   s&      .I$(!2(1%	%s   	 c                      \ rS rSr% Sr/ rS\S'   SS jrSS jrSS jr	\
 S       SS jj5       r\
 S     SS	 jj5       r\
SS
 j5       rSS jrSS jr\
SS j5       rSrg)ConstructorRegistry>   a  Registry for rules that define how types are constructed from
command-line arguments.

The behavior of CLIs generated by tyro are based on two types of rules.

*Primitive rules* should be a callable with the signature:

.. code-block: python

    (type_info: PrimitiveTypeInfo) -> PrimitiveConstructorSpec | UnsupportedTypeAnnotationError | None

where `None` is returned if the rule doesn't apply, and
`UnsupportedTypeAnnotationError` is returned if the rule applies but an
error was encountered. Each primitive rule defines behavior for a type that
can be instantiated from a single command-line argument.


*Struct rules* should be a callable with the signature:

.. code-block: python

    (type_info: StructTypeInfo) -> StructConstructorSpec | None

where `None` is returned if the rule doesn't apply. Each struct rule
defines behavior for a type that can be instantiated from multiple
command-line arguments.


To activate a registry, pass it directly to :func:`tyro.cli`:

.. code-block: python

    registry = ConstructorRegistry()
    tyro.cli(..., registry=registry)

For backward compatibility, you can also use the context manager pattern, though
the direct parameter approach is recommended:

.. code-block: python

    registry = ConstructorRegistry()
    with registry:
        tyro.cli(...)

z#ClassVar[list[ConstructorRegistry]]_active_registriesc                     / U l         / U l        g N_primitive_rules_struct_rules)selfs    r   __init__ConstructorRegistry.__init__o   s    9;35r   c                <    U R                   R                  U5        U$ )zDefine a rule for constructing a primitive type from a string. The
most recently added rule will be applied first.

Custom primitive rules will take precedence over both default primitive
rules and struct rules
)r(   appendr*   rules     r   primitive_rule"ConstructorRegistry.primitive_rules   s     	$$T*r   c                <    U R                   R                  U5        U$ )zrDefine a rule for constructing a primitive type from a string. The
most recently added rule will be applied first.)r)   r.   r/   s     r   struct_ruleConstructorRegistry.struct_rule~   s     	!!$'r   c                f    [        U R                  [        R                  " X5      US9[        5      $ )z$Check if a type is a primitive type.)nondefault_only)
isinstanceget_primitive_specr   maker   )clstypemarkersr7   s       r   _is_primitive_type&ConstructorRegistry._is_primitive_type   s9    
 ""!&&t5 #  %	
 	
r   c                6   U R                  5         UR                  b  UR                  $ U(       a  U R                  SS OU R                  SSS2    H-  nUR                  SSS2    H  nU" U5      nUc  M  Us  s  $    M/     [	        SUR
                   35      $ )z1Get a constructor specification for a given type.Nr   zUnsupported type annotation: )_ensure_defaults_initialized_primitive_specr$   r(   r   r<   )r;   	type_infor7   registryspec_factory
maybe_specs         r   r9   &ConstructorRegistry.get_primitive_spec   s     	((*$$0,,, +:C""12&s?U?U
B$H !) 9 9$B$ ?))4
)%% !@ .+INN+;<
 	
r   c                   U R                  5         [        5       (       ai  UR                  [        ;  aU  [        R
                  " UR                  UR                  5      (       d%  [        SUR                   SUR                   35      eUR                     U R                  SSS2    H6  nUR                  SSS2    H  nU" U5      nUc  M  Us  s  sSSS5        $    M8     SSS5        g! , (       d  f       g= f)zQGet a constructor specification for a given type. Returns `None` if
unsuccessful.z"Invalid default instance for type z: NrA   )rB   r   defaultr	   r   is_instancer<   r   _typevar_contextr$   r)   )r;   rD   rE   rF   rG   s        r   get_struct_spec#ConstructorRegistry.get_struct_spec   s    
 	((* $%%!!)DD)))..):K:KLL-4Y^^4DByGXGXFYZ  ''224R48$,$:$:4R4$@L!-i!8J!-)) ('$@ 9 (  (' s   4C+C+C++
C9c                    U R                   R                  5         U R                   nUR                  R                  U 5        g r&   )	__class__rB   r$   r.   )r*   r;   s     r   	__enter__ConstructorRegistry.__enter__   s/    335nn%%d+r   c                Z    U R                   nUR                  R                  5       U L d   eg r&   )rP   r$   pop)r*   argsr;   s      r   __exit__ConstructorRegistry.__exit__   s(    nn%%))+t333r   c                    [        U R                  5      S:X  a<  [        5       n[        U5        [	        U5        U R                  R                  U5        gg)z&Initialize default registry if needed.r   N)lenr$   r"   r   r   r.   )r;   rE   s     r   rB   0ConstructorRegistry._ensure_defaults_initialized   sJ     s%%&!+*,H *(3&x0""))(3 ,r   r'   N)returnNone)r0   PrimitiveSpecRuler[   r]   )r0   StructSpecRuler[   r^   )F)r<   r   r=   zset[Any]r7   r   r[   r   )rD   r   r7   r   r[   z9PrimitiveConstructorSpec | UnsupportedTypeAnnotationError)rD   r   r[   zStructConstructorSpec | None)rU   r   r[   r\   )__name__
__module____qualname____firstlineno____doc__r$   __annotations__r+   r1   r4   classmethodr>   r9   rM   rQ   rV   rB   __static_attributes__r   r   r   r"   r"   >   s    ,\ ?A;@6	 CH	
	
!)	
<@	
		
 	
 CH
)
<@
	B
 
,  0,4 	4 	4r   r"   )r[   r   )
__future__r   
contextlibr   typingr   r   r   r   tyro._singletonr	    r   rC   r   r   r   r   _struct_specr   r   r   r   r   rd   r]   r^   r   r   r    r"   r   r   r   <module>rm      s    " % 1 1 7    04 , 3	
"$BD
HIK  >*E2G2M,NNO&+ t +) 2 2"W4 W4r   