11from collections .abc import MutableMapping
22from pathlib import Path
3+ from typing import Any
34
45import tomlkit
56
6- data_home = Path .home () / "Library/Application Support" / " shelloracle"
7+ data_home = Path .home () / ". shelloracle"
78
89
910def _default_config () -> tomlkit .TOMLDocument :
@@ -20,27 +21,35 @@ class Configuration(MutableMapping):
2021 def __init__ (self ) -> None :
2122 self ._ensure_config_exists ()
2223
23- def __getitem__ (self , item ) :
24+ def __getitem__ (self , item : str ) -> dict :
2425 with self .filepath .open ("r" ) as file :
2526 config = tomlkit .load (file )
2627 return config [item ]
2728
28- def __setitem__ (self , key , value ) :
29+ def __setitem__ (self , key : str , value : Any ) -> None :
2930 with self .filepath .open ("r" ) as file :
3031 config = tomlkit .load (file )
3132 config [key ] = value
3233 config .multiline = True
3334 with self .filepath .open ("w" ) as file :
3435 tomlkit .dump (config , file )
3536
36- def __delitem__ (self , key ):
37- raise NotImplementedError ()
37+ def __delitem__ (self , key : str ) -> None :
38+ with self .filepath .open ("r" ) as file :
39+ config = tomlkit .load (file )
40+ del config [key ]
41+ with self .filepath .open ("w" ) as file :
42+ tomlkit .dump (config , file )
3843
39- def __iter__ (self ):
40- raise NotImplementedError ()
44+ def __iter__ (self ) -> None :
45+ with self .filepath .open ("r" ) as file :
46+ config = tomlkit .load (file )
47+ return iter (config )
4148
4249 def __len__ (self ) -> int :
43- raise NotImplementedError ()
50+ with self .filepath .open ("r" ) as file :
51+ config = tomlkit .load (file )
52+ return len (config )
4453
4554 def _ensure_config_exists (self ) -> None :
4655 if self .filepath .exists ():
0 commit comments