2
2
3
3
import os
4
4
from pathlib import Path
5
+ from typing import Any , Self
5
6
6
7
from tomlkit import exceptions , parse , table
7
8
@@ -14,10 +15,10 @@ class TomlConfig(BaseConfig):
14
15
def __init__ (self , * , data : bytes | str , path : Path | str ):
15
16
super ().__init__ ()
16
17
self .is_empty_config = False
17
- self .path = path # type: ignore
18
+ self .path : Path = path # type: ignore
18
19
self ._parse_setting (data )
19
20
20
- def init_empty_config_content (self ):
21
+ def init_empty_config_content (self ) -> None :
21
22
if os .path .isfile (self .path ):
22
23
with open (self .path , "rb" ) as input_toml_file :
23
24
parser = parse (input_toml_file .read ())
@@ -27,10 +28,10 @@ def init_empty_config_content(self):
27
28
with open (self .path , "wb" ) as output_toml_file :
28
29
if parser .get ("tool" ) is None :
29
30
parser ["tool" ] = table ()
30
- parser ["tool" ]["commitizen" ] = table ()
31
+ parser ["tool" ]["commitizen" ] = table () # type: ignore
31
32
output_toml_file .write (parser .as_string ().encode (self .encoding ))
32
33
33
- def set_key (self , key , value ) :
34
+ def set_key (self , key : str , value : Any ) -> Self :
34
35
"""Set or update a key in the conf.
35
36
36
37
For now only strings are supported.
@@ -39,7 +40,7 @@ def set_key(self, key, value):
39
40
with open (self .path , "rb" ) as f :
40
41
parser = parse (f .read ())
41
42
42
- parser ["tool" ]["commitizen" ][key ] = value
43
+ parser ["tool" ]["commitizen" ][key ] = value # type: ignore
43
44
with open (self .path , "wb" ) as f :
44
45
f .write (parser .as_string ().encode (self .encoding ))
45
46
return self
0 commit comments