55import base64
66import difflib
77import gzip
8+ import typing as t
89
910import click
1011
3536
3637
3738class LazyConfigAttributeDict (AttributeDict ):
38- """We want to avoid needlesly loading user config on every verdi invocation """
39+ """Subclass of ``AttributeDict`` that lazily calls :meth:`aiida.manage.configuration.get_config`. """
3940
4041 _LAZY_KEY = 'config'
4142
42- def __init__ (self , ctx , dictionary = None ):
43+ def __init__ (self , ctx : click . Context , dictionary : dict [ str , t . Any ] | None = None ):
4344 super ().__init__ (dictionary )
44- # We need click context so we can stop in case we fail to parse the config
4545 self .ctx = ctx
4646
47- def __getattr__ (self , attr ) :
48- """Override of AttributeDict.__getattr__ for lazy loading the config key.
47+ def __getattr__ (self , attr : str ) -> t . Any :
48+ """Override of `` AttributeDict.__getattr__`` for lazily loading the config key.
4949
50- Stops if config file cannot be parsed.
51- :raises AttributeError: if the attribute does not correspond to an existing key.
50+ :param attr: The attribute to return.
51+ :returns: The value of the attribute.
52+ :raises AttributeError: If the attribute does not correspond to an existing key.
53+ :raises click.exceptions.UsageError: If loading of the configuration fails.
5254 """
5355 if attr != self ._LAZY_KEY :
5456 return super ().__getattr__ (attr )
@@ -58,6 +60,7 @@ def __getattr__(self, attr):
5860 self [self ._LAZY_KEY ] = get_config (create = True )
5961 except ConfigurationError as exception :
6062 self .ctx .fail (str (exception ))
63+
6164 return self [self ._LAZY_KEY ]
6265
6366
0 commit comments