From 180ae000b22f432e3aac811d366d93dfb31f8559 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 23:37:02 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.7.3 → v0.8.1](https://github.com/astral-sh/ruff-pre-commit/compare/v0.7.3...v0.8.1) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dbc3d3e..cf45548 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,7 +15,7 @@ repos: args: [--py37-plus] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.7.3' + rev: 'v0.8.1' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix, --show-fixes] From feba900cd4d9a0bf45d39b061f9b8de651699c45 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 23:37:20 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_toml_tests.py | 7 ++++--- tomlkit/__init__.py | 6 +++--- tomlkit/items.py | 4 ++-- tomlkit/parser.py | 27 +++++++++++---------------- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/tests/test_toml_tests.py b/tests/test_toml_tests.py index 61e1281..9dca119 100644 --- a/tests/test_toml_tests.py +++ b/tests/test_toml_tests.py @@ -57,7 +57,8 @@ def test_invalid_decode(invalid_decode_case): def test_invalid_encode(invalid_encode_case): - with pytest.raises((TOMLKitError, UnicodeDecodeError)), open( - invalid_encode_case, encoding="utf-8" - ) as f: + with ( + pytest.raises((TOMLKitError, UnicodeDecodeError)), + open(invalid_encode_case, encoding="utf-8") as f, + ): load(f) diff --git a/tomlkit/__init__.py b/tomlkit/__init__.py index fbbab82..adb9781 100644 --- a/tomlkit/__init__.py +++ b/tomlkit/__init__.py @@ -29,6 +29,7 @@ __version__ = "0.13.2" __all__ = [ + "TOMLDocument", "aot", "array", "boolean", @@ -48,12 +49,11 @@ "loads", "nl", "parse", + "register_encoder", "string", "table", "time", - "TOMLDocument", + "unregister_encoder", "value", "ws", - "register_encoder", - "unregister_encoder", ] diff --git a/tomlkit/items.py b/tomlkit/items.py index b46679b..fe2b56a 100644 --- a/tomlkit/items.py +++ b/tomlkit/items.py @@ -1083,7 +1083,7 @@ def _getstate(self, protocol: int = 3) -> tuple: class _ArrayItemGroup: - __slots__ = ("value", "indent", "comma", "comment") + __slots__ = ("comma", "comment", "indent", "value") def __init__( self, @@ -1260,7 +1260,7 @@ def add_line( data_values = [] for i, el in enumerate(items): it = item(el, _parent=self) - if isinstance(it, Comment) or add_comma and isinstance(el, Whitespace): + if isinstance(it, Comment) or (add_comma and isinstance(el, Whitespace)): raise ValueError(f"item type {type(it)} is not allowed in add_line") if not isinstance(it, Whitespace): if whitespace: diff --git a/tomlkit/parser.py b/tomlkit/parser.py index b73f277..77e73e7 100644 --- a/tomlkit/parser.py +++ b/tomlkit/parser.py @@ -264,7 +264,7 @@ def _parse_comment_trail(self, parse_trail: bool = True) -> tuple[str, str, str] # The comment itself while not self.end() and not self._current.is_nl(): code = ord(self._current) - if code == CHR_DEL or code <= CTRL_CHAR_LIMIT and code != CTRL_I: + if code == CHR_DEL or (code <= CTRL_CHAR_LIMIT and code != CTRL_I): raise self.parse_error(InvalidControlChar, code, "comments") if not self.inc(): @@ -636,10 +636,8 @@ def _parse_inline_table(self) -> InlineTable: self.inc() break - if ( - trailing_comma is False - or trailing_comma is None - and self._current == "," + if trailing_comma is False or ( + trailing_comma is None and self._current == "," ): # Either the previous key-value pair was not followed by a comma # or the table has an unexpected leading comma. @@ -675,10 +673,8 @@ def _parse_number(self, raw: str, trivia: Trivia) -> Item | None: raw = raw[1:] if len(raw) > 1 and ( - raw.startswith("0") - and not raw.startswith(("0.", "0o", "0x", "0b", "0e")) - or sign - and raw.startswith(".") + (raw.startswith("0") and not raw.startswith(("0.", "0o", "0x", "0b", "0e"))) + or (sign and raw.startswith(".")) ): return None @@ -703,10 +699,8 @@ def _parse_number(self, raw: str, trivia: Trivia) -> Item | None: if "_" in clean: return None - if ( - clean.endswith(".") - or not clean.startswith("0x") - and clean.split("e", 1)[0].endswith(".") + if clean.endswith(".") or ( + not clean.startswith("0x") and clean.split("e", 1)[0].endswith(".") ): return None @@ -817,14 +811,15 @@ def _parse_string(self, delim: StringType) -> String: if ( delim.is_singleline() and not escaped - and (code == CHR_DEL or code <= CTRL_CHAR_LIMIT and code != CTRL_I) + and (code == CHR_DEL or (code <= CTRL_CHAR_LIMIT and code != CTRL_I)) ) or ( delim.is_multiline() and not escaped and ( code == CHR_DEL - or code <= CTRL_CHAR_LIMIT - and code not in [CTRL_I, CTRL_J, CTRL_M] + or ( + code <= CTRL_CHAR_LIMIT and code not in [CTRL_I, CTRL_J, CTRL_M] + ) ) ): raise self.parse_error(InvalidControlChar, code, "strings")