diff --git a/config/scheme.py b/config/scheme.py index a5846ba..ee3f161 100644 --- a/config/scheme.py +++ b/config/scheme.py @@ -73,6 +73,9 @@ class ProfilesSection(DictScheme): current: str default: SparseProfile + def __init__(self, *kargs, allow_extra: bool = True, **kwargs): + super().__init__(*kargs, allow_extra=allow_extra, **kwargs) # type: ignore[misc] + @classmethod def transform(cls, values: Mapping[str, Any], validate: bool = True, allow_extra: bool = True, type_hints: Optional[dict[str, Any]] = None): results = {} @@ -84,11 +87,11 @@ class ProfilesSection(DictScheme): raise Exception(f'Unknown key {k} in profiles section (Hint: extra_keys not allowed for some reason)') if not isinstance(v, dict): raise Exception(f'profile {v} is not a dict!') - results[k] = SparseProfile.fromDict(v, validate=True) + results[k] = SparseProfile.fromDict(v, validate=True, allow_extra=allow_extra) return results - def update(self, d, validate: bool = True): - Munch.update(self, self.transform(values=d, validate=validate)) + def update(self, d, validate: bool = True, **kwargs): # type: ignore[override] + Munch.update(self, self.transform(values=d, validate=validate, **kwargs)) def __repr__(self): return f'{type(self)}{dict.__repr__(self.toDict())}' @@ -103,12 +106,12 @@ class Config(DictScheme): profiles: ProfilesSection @classmethod - def fromDict( - cls, - values: Mapping[str, Any], - validate: bool = True, - allow_extra: bool = False, - allow_incomplete: bool = False, + def fromDict( # type: ignore[override] + cls, + values: Mapping[str, Any], + validate: bool = True, + allow_extra: bool = False, + allow_incomplete: bool = False, ): values = dict(values) # copy for later modification _vals = {} @@ -119,7 +122,7 @@ class Config(DictScheme): continue value = values.pop(name) if not isinstance(value, _class): - value = _class.fromDict(value, validate=validate) + value = _class(value, validate=validate) _vals[name] = value if values: diff --git a/devices/deviceinfo.py b/devices/deviceinfo.py index 2a86bf2..d19ee60 100644 --- a/devices/deviceinfo.py +++ b/devices/deviceinfo.py @@ -269,5 +269,5 @@ def parse_deviceinfo(deviceinfo_lines: list[str], device_name: str, kernel='main if 'arch' in info: arch = info['arch'] info['arch'] = PMOS_ARCHES_OVERRIDES.get(arch, arch) # type: ignore[arg-type] - dev = DeviceInfo.fromDict(info) + dev = DeviceInfo.fromDict(info, allow_extra=True) return dev diff --git a/dictscheme.py b/dictscheme.py index ca7c12c..46c61cc 100644 --- a/dictscheme.py +++ b/dictscheme.py @@ -51,8 +51,8 @@ class DictScheme(Munch): _strip_hidden: ClassVar[bool] = False _sparse: ClassVar[bool] = False - def __init__(self, d: Mapping = {}, validate: bool = True, **kwargs): - self.update(dict(d) | kwargs, validate=validate) + def __init__(self, d: Mapping = {}, validate: bool = True, allow_extra: bool = False, **kwargs): + self.update(dict(d) | kwargs, validate=validate, allow_extra=allow_extra) @classmethod def transform( @@ -162,8 +162,8 @@ class DictScheme(Munch): return results @classmethod - def fromDict(cls, values: Mapping[str, Any], validate: bool = True): - return cls(d=values, validate=validate) + def fromDict(cls, values: Mapping[str, Any], validate: bool = True, **kwargs): + return cls(d=values, validate=validate, **kwargs) def toDict( self, @@ -251,8 +251,8 @@ class DictScheme(Munch): ) return result - def update(self, d: Mapping[str, Any], validate: bool = True): - Munch.update(self, type(self).transform(d, validate=validate)) + def update(self, d: Mapping[str, Any], validate: bool = True, allow_extra: bool = False): + Munch.update(self, type(self).transform(d, validate=validate, allow_extra=allow_extra)) def __init_subclass__(cls): super().__init_subclass__() diff --git a/distro/repo_config.py b/distro/repo_config.py index 88092af..f5f63ab 100644 --- a/distro/repo_config.py +++ b/distro/repo_config.py @@ -51,8 +51,8 @@ class ReposConfigFile(DictScheme): _strip_hidden: ClassVar[bool] = True _sparse: ClassVar[bool] = True - def __init__(self, d, **kwargs): - super().__init__(d=d, **kwargs) + def __init__(self, d, *, allow_extra: bool = True, **kwargs): + super().__init__(d=d, allow_extra=allow_extra, **kwargs) self[REPOS_KEY] = self.get(REPOS_KEY, {}) for repo_cls, defaults, repos, remote_url in [ (RepoConfig, REPO_DEFAULTS, self.get(REPOS_KEY), d.get(REMOTEURL_KEY, None)), @@ -66,6 +66,9 @@ class ReposConfigFile(DictScheme): _repo[REMOTEURL_KEY] = remote_url repos[name] = repo_cls(_repo, **kwargs) + def update(self, *kargs, allow_extra: bool = True, **kwargs): + return super().update(*kargs, allow_extra=allow_extra, **kwargs) # type: ignore[misc] + @staticmethod def parse_config(path: str) -> ReposConfigFile: try: