Skip to content

Commit

Permalink
Update linter config & reformat code with black
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasha10 committed Feb 27, 2024
1 parent dc42c30 commit 073786d
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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]
Expand Down
44 changes: 16 additions & 28 deletions omegaconf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

def _dereference_node(self) -> "Node":
node = self._dereference_node_impl(throw_on_resolution_failure=True)
Expand Down Expand Up @@ -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: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

@abstractmethod
def __ne__(self, other: Any) -> bool:
...
def __ne__(self, other: Any) -> bool: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

@abstractmethod
def __hash__(self) -> int:
...
def __hash__(self) -> int: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

@abstractmethod
def _value(self) -> Any:
...
def _value(self) -> Any: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

@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: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

@abstractmethod
def _is_optional(self) -> bool:
...
def _is_optional(self) -> bool: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

@abstractmethod
def _is_interpolation(self) -> bool:
...
def _is_interpolation(self) -> bool: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

def _key(self) -> Any:
return self._metadata.key
Expand Down Expand Up @@ -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]]]: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

@abstractmethod
def _get_node(
Expand All @@ -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]]]: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

@abstractmethod
def __delitem__(self, key: Any) -> None:
...
def __delitem__(self, key: Any) -> None: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

@abstractmethod
def __setitem__(self, key: Any, value: Any) -> None:
...
def __setitem__(self, key: Any, value: Any) -> None: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

@abstractmethod
def __iter__(self) -> Iterator[Any]:
...
def __iter__(self) -> Iterator[Any]: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

@abstractmethod
def __getitem__(self, key_or_index: Any) -> Any:
...
def __getitem__(self, key_or_index: Any) -> Any: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

def _resolve_key_and_root(self, key: str) -> Tuple["Container", str]:
orig = key
Expand Down
9 changes: 3 additions & 6 deletions omegaconf/basecontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

def __len__(self) -> int:
if self._is_none() or self._is_missing() or self._is_interpolation():
Expand Down Expand Up @@ -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: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

@abstractmethod
def _validate_set(self, key: Any, value: Any) -> None:
...
def _validate_set(self, key: Any, value: Any) -> None: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

def _value(self) -> Any:
return self.__dict__["_content"]
Expand Down
3 changes: 1 addition & 2 deletions omegaconf/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

def __str__(self) -> str:
return str(self._val)
Expand Down
16 changes: 6 additions & 10 deletions omegaconf/omegaconf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""OmegaConf module"""

import copy
import inspect
import io
Expand Down Expand Up @@ -129,44 +130,39 @@ def create(
obj: str,
parent: Optional[BaseContainer] = None,
flags: Optional[Dict[str, bool]] = None,
) -> Union[DictConfig, ListConfig]:
...
) -> Union[DictConfig, ListConfig]: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

@staticmethod
@overload
def create(
obj: Union[List[Any], Tuple[Any, ...]],
parent: Optional[BaseContainer] = None,
flags: Optional[Dict[str, bool]] = None,
) -> ListConfig:
...
) -> ListConfig: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

@staticmethod
@overload
def create(
obj: DictConfig,
parent: Optional[BaseContainer] = None,
flags: Optional[Dict[str, bool]] = None,
) -> DictConfig:
...
) -> DictConfig: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

@staticmethod
@overload
def create(
obj: ListConfig,
parent: Optional[BaseContainer] = None,
flags: Optional[Dict[str, bool]] = None,
) -> ListConfig:
...
) -> ListConfig: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

@staticmethod
@overload
def create(
obj: Optional[Dict[Any, Any]] = None,
parent: Optional[BaseContainer] = None,
flags: Optional[Dict[str, bool]] = None,
) -> DictConfig:
...
) -> DictConfig: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

@staticmethod
def create( # noqa F811
Expand Down
6 changes: 3 additions & 3 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def __eq__(self, other: Any) -> bool:
T = TypeVar("T")


class IllegalTypeGeneric(Generic[T]):
...
class IllegalTypeGeneric(Generic[T]): ...

Check notice

Code scanning / CodeQL

Statement has no effect Note test

This statement has no effect.


class NonCopyableIllegalType:
Expand Down
1 change: 1 addition & 0 deletions tests/test_compare_dictconfig_vs_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/test_create.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Testing for OmegaConf"""

import platform
import re
import sys
Expand Down
16 changes: 10 additions & 6 deletions tests/test_omegaconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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),
Expand Down
13 changes: 9 additions & 4 deletions tests/test_to_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
],
)
Expand Down

0 comments on commit 073786d

Please sign in to comment.