@@ -26,7 +26,7 @@ def __init__(self, content: "RawConfigData") -> None:
2626 self .content = content
2727
2828 @staticmethod
29- def _load (format : "FormatLiteral" , content : str ) -> dict [str , t .Any ]:
29+ def _load (fmt : "FormatLiteral" , content : str ) -> dict [str , t .Any ]:
3030 """Load raw config data and directly return it.
3131
3232 >>> ConfigReader._load("json", '{ "session_name": "my session" }')
@@ -35,21 +35,22 @@ def _load(format: "FormatLiteral", content: str) -> dict[str, t.Any]:
3535 >>> ConfigReader._load("yaml", 'session_name: my session')
3636 {'session_name': 'my session'}
3737 """
38- if format == "yaml" :
38+ if fmt == "yaml" :
3939 return t .cast (
4040 dict [str , t .Any ],
4141 yaml .load (
4242 content ,
4343 Loader = yaml .SafeLoader ,
4444 ),
4545 )
46- elif format == "json" :
46+ elif fmt == "json" :
4747 return t .cast (dict [str , t .Any ], json .loads (content ))
4848 else :
49- raise NotImplementedError (f"{ format } not supported in configuration" )
49+ msg = f"{ fmt } not supported in configuration"
50+ raise NotImplementedError (msg )
5051
5152 @classmethod
52- def load (cls , format : "FormatLiteral" , content : str ) -> "ConfigReader" :
53+ def load (cls , fmt : "FormatLiteral" , content : str ) -> "ConfigReader" :
5354 """Load raw config data into a ConfigReader instance (to dump later).
5455
5556 >>> cfg = ConfigReader.load("json", '{ "session_name": "my session" }')
@@ -66,7 +67,7 @@ def load(cls, format: "FormatLiteral", content: str) -> "ConfigReader":
6667 """
6768 return cls (
6869 content = cls ._load (
69- format = format ,
70+ fmt = fmt ,
7071 content = content ,
7172 ),
7273 )
@@ -105,14 +106,15 @@ def _from_file(cls, path: pathlib.Path) -> dict[str, t.Any]:
105106 content = path .open ().read ()
106107
107108 if path .suffix in [".yaml" , ".yml" ]:
108- format : "FormatLiteral" = "yaml"
109+ fmt : "FormatLiteral" = "yaml"
109110 elif path .suffix == ".json" :
110- format = "json"
111+ fmt = "json"
111112 else :
112- raise NotImplementedError (f"{ path .suffix } not supported in { path } " )
113+ msg = f"{ path .suffix } not supported in { path } "
114+ raise NotImplementedError (msg )
113115
114116 return cls ._load (
115- format = format ,
117+ fmt = fmt ,
116118 content = content ,
117119 )
118120
@@ -158,7 +160,7 @@ def from_file(cls, path: pathlib.Path) -> "ConfigReader":
158160
159161 @staticmethod
160162 def _dump (
161- format : "FormatLiteral" ,
163+ fmt : "FormatLiteral" ,
162164 content : "RawConfigData" ,
163165 indent : int = 2 ,
164166 ** kwargs : t .Any ,
@@ -171,22 +173,23 @@ def _dump(
171173 >>> ConfigReader._dump("json", { "session_name": "my session" })
172174 '{\n "session_name": "my session"\n}'
173175 """
174- if format == "yaml" :
176+ if fmt == "yaml" :
175177 return yaml .dump (
176178 content ,
177179 indent = 2 ,
178180 default_flow_style = False ,
179181 Dumper = yaml .SafeDumper ,
180182 )
181- elif format == "json" :
183+ elif fmt == "json" :
182184 return json .dumps (
183185 content ,
184186 indent = 2 ,
185187 )
186188 else :
187- raise NotImplementedError (f"{ format } not supported in config" )
189+ msg = f"{ fmt } not supported in config"
190+ raise NotImplementedError (msg )
188191
189- def dump (self , format : "FormatLiteral" , indent : int = 2 , ** kwargs : t .Any ) -> str :
192+ def dump (self , fmt : "FormatLiteral" , indent : int = 2 , ** kwargs : t .Any ) -> str :
190193 r"""Dump via ConfigReader instance.
191194
192195 >>> cfg = ConfigReader({ "session_name": "my session" })
@@ -196,7 +199,7 @@ def dump(self, format: "FormatLiteral", indent: int = 2, **kwargs: t.Any) -> str
196199 '{\n "session_name": "my session"\n}'
197200 """
198201 return self ._dump (
199- format = format ,
202+ fmt = fmt ,
200203 content = self .content ,
201204 indent = indent ,
202205 ** kwargs ,
0 commit comments