o
    ]÷¡iÛ  ã                   @   s,   d Z ddlmZ G dd„ deƒZdd„ ZdS )zConfigDict config file.é    )Úconfig_dictc                   @   s:   e Zd ZdZdd„ Zdd„ Zedd„ ƒZejdd„ ƒZd	S )
ÚUnusableConfiga<  Test against code assuming the semantics of attributes (such as `lock`).

  This class is to test that the flags implementation does not assume the
  semantics of attributes. This is to avoid code such as:

  ```python
  if hasattr(obj, lock):
    obj.lock()
  ```

  which will fail if `obj` has an attribute `lock` that does not behave in the
  way we expect.

  This class only has unusable attributes. There are two
  exceptions for which this class behaves normally:
  * Python's special functions which start and end with a double underscore.
  * `valid_attribute`, an attribute used to test the class.

  For other attributes, both `hasttr(obj, attr)` and `callable(obj, attr)` will
  return True. Calling `obj.attr` will return a function which takes no
  arguments and raises an AttributeError when called. For example, the `lock`
  example above will raise an AttributeError. The only valid action on
  attributes is assignment, e.g.

  ```python
  obj = UnusableConfig()
  obj.attr = 1
  ```

  In which case the attribute will keep its assigned value and become usable.
  c                 C   s
   d| _ d S )Né   ©Ú_valid_attribute©Úself© r	   úg/home/ubuntu/.local/lib/python3.10/site-packages/ml_collections/config_flags/tests/configdict_config.pyÚ__init__5   s   
zUnusableConfig.__init__c                    s2   ˆ   d¡rˆ  d¡rtd ˆ ¡ƒ‚‡ fdd„}|S )aë  Get an arbitrary attribute.

    Returns a function which takes no arguments and raises an AttributeError,
    except for Python special functions in which case an AttributeError is
    directly raised.

    Args:
      attribute: A string representing the attribute's name.
    Returns:
      A function which raises an AttributeError when called.
    Raises:
      AttributeError: when the attribute is a Python special function starting
          and ending with a double underscore.
    Ú__z)UnusableConfig does not contain entry {}.c                      s   t d ˆ ¡ƒ‚)Nz.{} is not a usable attribute of UnusableConfig)ÚAttributeErrorÚformatr	   ©Ú	attributer	   r
   Úraise_attribute_error_funK   s
   ÿÿz=UnusableConfig.__getattr__.<locals>.raise_attribute_error_fun)Ú
startswithÚendswithr   r   )r   r   r   r	   r   r
   Ú__getattr__8   s   ÿzUnusableConfig.__getattr__c                 C   s   | j S ©Nr   r   r	   r	   r
   Úvalid_attributeR   s   zUnusableConfig.valid_attributec                 C   s
   || _ d S r   r   )r   Úvaluer	   r	   r
   r   V   s   
N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Úpropertyr   Úsetterr	   r	   r	   r
   r      s     
r   c                  C   sN   t  ¡ } d| _t  d¡| _g d¢| _g d¢g| _t  ¡ | _d| j_tƒ | _	| S )z%Returns a ConfigDict. Used for tests.r   )r   é   é   )
r   Ú
ConfigDictÚintegerÚFieldReferenceÚ	referenceÚlistÚnested_listÚnested_configdictr   Úunusable_config)Úcfgr	   r	   r
   Ú
get_configZ   s   

r)   N)r   Úml_collectionsr   Úobjectr   r)   r	   r	   r	   r
   Ú<module>   s   F