diff --git a/.flake8 b/.flake8 index 78ef79828..77362290d 100644 --- a/.flake8 +++ b/.flake8 @@ -2,4 +2,4 @@ exclude = .git,.nox,.tox,omegaconf/grammar/gen,build,omegaconf/vendor max-line-length = 119 select = E,F,W,C -ignore=W503,E203 +ignore=W503,E203,E701,E704 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3bec811c9..36b048637 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,12 +4,12 @@ default_language_version: # Hook versions should match those in requirements/dev.txt repos: - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort - repo: https://github.com/psf/black - rev: 23.7.0 + rev: 24.2.0 hooks: - id: black @@ -19,7 +19,7 @@ repos: - id: flake8 - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.4.1 + rev: v1.8.0 hooks: - id: mypy args: [--strict] diff --git a/omegaconf/base.py b/omegaconf/base.py index ed52ec42c..39667d9df 100644 --- a/omegaconf/base.py +++ b/omegaconf/base.py @@ -237,8 +237,7 @@ def _format_and_raise( assert False @abstractmethod - def _get_full_key(self, key: Optional[Union[DictKeyType, int]]) -> str: - ... + def _get_full_key(self, key: Optional[Union[DictKeyType, int]]) -> str: ... def _dereference_node(self) -> "Node": node = self._dereference_node_impl(throw_on_resolution_failure=True) @@ -306,32 +305,27 @@ def _is_none(self) -> bool: return self._value() is None @abstractmethod - def __eq__(self, other: Any) -> bool: - ... + def __eq__(self, other: Any) -> bool: ... @abstractmethod - def __ne__(self, other: Any) -> bool: - ... + def __ne__(self, other: Any) -> bool: ... @abstractmethod - def __hash__(self) -> int: - ... + def __hash__(self) -> int: ... @abstractmethod - def _value(self) -> Any: - ... + def _value(self) -> Any: ... @abstractmethod - def _set_value(self, value: Any, flags: Optional[Dict[str, bool]] = None) -> None: - ... + def _set_value( + self, value: Any, flags: Optional[Dict[str, bool]] = None + ) -> None: ... @abstractmethod - def _is_optional(self) -> bool: - ... + def _is_optional(self) -> bool: ... @abstractmethod - def _is_interpolation(self) -> bool: - ... + def _is_interpolation(self) -> bool: ... def _key(self) -> Any: return self._metadata.key @@ -414,8 +408,7 @@ def _get_child( validate_key: bool = True, throw_on_missing_value: bool = False, throw_on_missing_key: bool = False, - ) -> Union[Optional[Node], List[Optional[Node]]]: - ... + ) -> Union[Optional[Node], List[Optional[Node]]]: ... @abstractmethod def _get_node( @@ -425,24 +418,19 @@ def _get_node( validate_key: bool = True, throw_on_missing_value: bool = False, throw_on_missing_key: bool = False, - ) -> Union[Optional[Node], List[Optional[Node]]]: - ... + ) -> Union[Optional[Node], List[Optional[Node]]]: ... @abstractmethod - def __delitem__(self, key: Any) -> None: - ... + def __delitem__(self, key: Any) -> None: ... @abstractmethod - def __setitem__(self, key: Any, value: Any) -> None: - ... + def __setitem__(self, key: Any, value: Any) -> None: ... @abstractmethod - def __iter__(self) -> Iterator[Any]: - ... + def __iter__(self) -> Iterator[Any]: ... @abstractmethod - def __getitem__(self, key_or_index: Any) -> Any: - ... + def __getitem__(self, key_or_index: Any) -> Any: ... def _resolve_key_and_root(self, key: str) -> Tuple["Container", str]: orig = key diff --git a/omegaconf/basecontainer.py b/omegaconf/basecontainer.py index a83907f8e..684a6e429 100644 --- a/omegaconf/basecontainer.py +++ b/omegaconf/basecontainer.py @@ -167,8 +167,7 @@ def __setstate__(self, d: Dict[str, Any]) -> None: self.__dict__.update(d) @abstractmethod - def __delitem__(self, key: Any) -> None: - ... + def __delitem__(self, key: Any) -> None: ... def __len__(self) -> int: if self._is_none() or self._is_missing() or self._is_interpolation(): @@ -722,12 +721,10 @@ def _is_interpolation(self) -> bool: return _is_interpolation(self.__dict__["_content"]) @abstractmethod - def _validate_get(self, key: Any, value: Any = None) -> None: - ... + def _validate_get(self, key: Any, value: Any = None) -> None: ... @abstractmethod - def _validate_set(self, key: Any, value: Any) -> None: - ... + def _validate_set(self, key: Any, value: Any) -> None: ... def _value(self) -> Any: return self.__dict__["_content"] diff --git a/omegaconf/nodes.py b/omegaconf/nodes.py index 1f02cde65..c3f7ba6ca 100644 --- a/omegaconf/nodes.py +++ b/omegaconf/nodes.py @@ -76,8 +76,7 @@ def validate_and_convert(self, value: Any) -> Any: return self._validate_and_convert_impl(value) @abstractmethod - def _validate_and_convert_impl(self, value: Any) -> Any: - ... + def _validate_and_convert_impl(self, value: Any) -> Any: ... def __str__(self) -> str: return str(self._val) diff --git a/omegaconf/omegaconf.py b/omegaconf/omegaconf.py index 8b130895b..6dbf2e7b8 100644 --- a/omegaconf/omegaconf.py +++ b/omegaconf/omegaconf.py @@ -1,4 +1,5 @@ """OmegaConf module""" + import copy import inspect import io @@ -129,8 +130,7 @@ def create( obj: str, parent: Optional[BaseContainer] = None, flags: Optional[Dict[str, bool]] = None, - ) -> Union[DictConfig, ListConfig]: - ... + ) -> Union[DictConfig, ListConfig]: ... @staticmethod @overload @@ -138,8 +138,7 @@ def create( obj: Union[List[Any], Tuple[Any, ...]], parent: Optional[BaseContainer] = None, flags: Optional[Dict[str, bool]] = None, - ) -> ListConfig: - ... + ) -> ListConfig: ... @staticmethod @overload @@ -147,8 +146,7 @@ def create( obj: DictConfig, parent: Optional[BaseContainer] = None, flags: Optional[Dict[str, bool]] = None, - ) -> DictConfig: - ... + ) -> DictConfig: ... @staticmethod @overload @@ -156,8 +154,7 @@ def create( obj: ListConfig, parent: Optional[BaseContainer] = None, flags: Optional[Dict[str, bool]] = None, - ) -> ListConfig: - ... + ) -> ListConfig: ... @staticmethod @overload @@ -165,8 +162,7 @@ def create( obj: Optional[Dict[Any, Any]] = None, parent: Optional[BaseContainer] = None, flags: Optional[Dict[str, bool]] = None, - ) -> DictConfig: - ... + ) -> DictConfig: ... @staticmethod def create( # noqa F811 diff --git a/requirements/dev.txt b/requirements/dev.txt index 6f7b94444..30bf623be 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,12 +1,12 @@ -r base.txt -r docs.txt attrs -black==23.7.0 +black==24.2.0 build coveralls flake8==6.0.0 -isort==5.12.0 -mypy==1.4.1 +isort==5.13.2 +mypy==1.8.0 nox pre-commit pyflakes diff --git a/tests/__init__.py b/tests/__init__.py index 4f953f1ec..185ae0d0e 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -22,8 +22,7 @@ def __eq__(self, other: Any) -> bool: T = TypeVar("T") -class IllegalTypeGeneric(Generic[T]): - ... +class IllegalTypeGeneric(Generic[T]): ... class NonCopyableIllegalType: diff --git a/tests/test_compare_dictconfig_vs_dict.py b/tests/test_compare_dictconfig_vs_dict.py index c868c4c16..953331675 100644 --- a/tests/test_compare_dictconfig_vs_dict.py +++ b/tests/test_compare_dictconfig_vs_dict.py @@ -18,6 +18,7 @@ TestPrimitiveTypeDunderMethods: for DictConfig where key_type is primitive TestEnumTypeDunderMethods: for DictConfig where key_type is Enum """ + from copy import deepcopy from enum import Enum from typing import Any, Dict, Optional diff --git a/tests/test_create.py b/tests/test_create.py index 66b073cd8..db657d72d 100644 --- a/tests/test_create.py +++ b/tests/test_create.py @@ -1,4 +1,5 @@ """Testing for OmegaConf""" + import platform import re import sys diff --git a/tests/test_omegaconf.py b/tests/test_omegaconf.py index 1097eb5af..aa340e857 100644 --- a/tests/test_omegaconf.py +++ b/tests/test_omegaconf.py @@ -392,9 +392,11 @@ def test_is_interpolation(fac: Any) -> Any: ({"foo": FloatNode(None)}, type(None)), ( {"foo": Path("hello.txt")}, - pathlib.WindowsPath - if platform.system() == "Windows" - else pathlib.PosixPath, + ( + pathlib.WindowsPath + if platform.system() == "Windows" + else pathlib.PosixPath + ), ), ({"foo": "bar"}, str), ({"foo": None}, type(None)), @@ -420,9 +422,11 @@ def test_get_type(cfg: Any, type_: Any) -> None: (b"123", bytes), ( Path("hello.txt"), - pathlib.WindowsPath - if platform.system() == "Windows" - else pathlib.PosixPath, + ( + pathlib.WindowsPath + if platform.system() == "Windows" + else pathlib.PosixPath + ), ), ("foo", str), (DictConfig(content={}), dict), diff --git a/tests/test_to_yaml.py b/tests/test_to_yaml.py index 44b134edd..b85ee2f59 100644 --- a/tests/test_to_yaml.py +++ b/tests/test_to_yaml.py @@ -19,9 +19,11 @@ ({b"abc": "bytes key"}, "? !!binary |\n YWJj\n: bytes key\n"), ( {"path_value": Path("hello.txt")}, - "path_value: !!python/object/apply:pathlib.WindowsPath\n- hello.txt\n" - if platform.system() == "Windows" - else "path_value: !!python/object/apply:pathlib.PosixPath\n- hello.txt\n", + ( + "path_value: !!python/object/apply:pathlib.WindowsPath\n- hello.txt\n" + if platform.system() == "Windows" + else "path_value: !!python/object/apply:pathlib.PosixPath\n- hello.txt\n" + ), ), ({123: "int key"}, "123: int key\n"), ({123.45: "float key"}, "123.45: float key\n"), @@ -39,7 +41,10 @@ def test_to_yaml(input_: Any, expected: str) -> None: @mark.parametrize( "input_, expected", [ - (["item一", "item二", dict(key三="value三")], "- item一\n- item二\n- key三: value三\n"), + ( + ["item一", "item二", dict(key三="value三")], + "- item一\n- item二\n- key三: value三\n", + ), (dict(你好="世界", list=[1, 2]), "你好: 世界\nlist:\n- 1\n- 2\n"), ], )