Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 25, 2024
1 parent 794d866 commit af9ce97
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
7 changes: 4 additions & 3 deletions tests/test_toml_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 3 additions & 3 deletions tomlkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

__version__ = "0.13.2"
__all__ = [
"TOMLDocument",
"aot",
"array",
"boolean",
Expand All @@ -48,12 +49,11 @@
"loads",
"nl",
"parse",
"register_encoder",
"string",
"table",
"time",
"TOMLDocument",
"unregister_encoder",
"value",
"ws",
"register_encoder",
"unregister_encoder",
]
4 changes: 2 additions & 2 deletions tomlkit/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
27 changes: 11 additions & 16 deletions tomlkit/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit af9ce97

Please sign in to comment.