Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pre-commit.ci] pre-commit autoupdate #386

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
args: [--py37-plus]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.7.3'
rev: 'v0.8.0'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]
Expand Down
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
Loading