dict_config_source.py (poetry-1.1.15) | : | dict_config_source.py (poetry-1.2.0) | ||
---|---|---|---|---|
from __future__ import annotations | ||||
from typing import Any | from typing import Any | |||
from typing import Dict | ||||
from .config_source import ConfigSource | from poetry.config.config_source import ConfigSource | |||
class DictConfigSource(ConfigSource): | class DictConfigSource(ConfigSource): | |||
def __init__(self): # type: () -> None | def __init__(self) -> None: | |||
self._config = {} | self._config: dict[str, Any] = {} | |||
@property | @property | |||
def config(self): # type: () -> Dict[str, Any] | def config(self) -> dict[str, Any]: | |||
return self._config | return self._config | |||
def add_property(self, key, value): # type: (str, Any) -> None | def add_property(self, key: str, value: Any) -> None: | |||
keys = key.split(".") | keys = key.split(".") | |||
config = self._config | config = self._config | |||
for i, key in enumerate(keys): | for i, key in enumerate(keys): | |||
if key not in config and i < len(keys) - 1: | if key not in config and i < len(keys) - 1: | |||
config[key] = {} | config[key] = {} | |||
if i == len(keys) - 1: | if i == len(keys) - 1: | |||
config[key] = value | config[key] = value | |||
break | break | |||
config = config[key] | config = config[key] | |||
def remove_property(self, key): # type: (str) -> None | def remove_property(self, key: str) -> None: | |||
keys = key.split(".") | keys = key.split(".") | |||
config = self._config | config = self._config | |||
for i, key in enumerate(keys): | for i, key in enumerate(keys): | |||
if key not in config: | if key not in config: | |||
return | return | |||
if i == len(keys) - 1: | if i == len(keys) - 1: | |||
del config[key] | del config[key] | |||
End of changes. 7 change blocks. | ||||
7 lines changed or deleted | 8 lines changed or added |