MCPcopy Create free account
hub / github.com/modelscope/modelscope / __init__

Method __init__

modelscope/utils/config.py:203–225  ·  view source on GitHub ↗
(self, cfg_dict=None, cfg_text=None, filename=None)

Source from the content-addressed store, hash-verified

201 return cfg
202
203 def __init__(self, cfg_dict=None, cfg_text=None, filename=None):
204 if cfg_dict is None:
205 cfg_dict = dict()
206 elif not isinstance(cfg_dict, dict):
207 raise TypeError('cfg_dict must be a dict, but '
208 f'got {type(cfg_dict)}')
209 for key in cfg_dict:
210 if key in RESERVED_KEYS:
211 raise KeyError(f'{key} is reserved for config file')
212
213 if isinstance(filename, Path):
214 filename = str(filename)
215
216 super(Config, self).__setattr__('_cfg_dict', ConfigDict(cfg_dict))
217 super(Config, self).__setattr__('_filename', filename)
218 if cfg_text:
219 text = cfg_text
220 elif filename:
221 with open(filename, 'r', encoding='utf-8') as f:
222 text = f.read()
223 else:
224 text = ''
225 super(Config, self).__setattr__('_text', text)
226
227 @property
228 def filename(self):

Callers

nothing calls this directly

Calls 3

ConfigDictClass · 0.85
__setattr__Method · 0.45
readMethod · 0.45

Tested by

no test coverage detected