Skip to content

Commit 800c829

Browse files
[pre-commit.ci] pre-commit autoupdate (#386)
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/asottile/pyupgrade: v3.19.0 → v3.19.1](asottile/pyupgrade@v3.19.0...v3.19.1) - [github.com/astral-sh/ruff-pre-commit: v0.7.3 → v0.9.1](astral-sh/ruff-pre-commit@v0.7.3...v0.9.1) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * chore(deps-dev): bump virtualenv from 20.26.1 to 20.26.6 (#394) Bumps [virtualenv](https://github.com/pypa/virtualenv) from 20.26.1 to 20.26.6. - [Release notes](https://github.com/pypa/virtualenv/releases) - [Changelog](https://github.com/pypa/virtualenv/blob/main/docs/changelog.rst) - [Commits](pypa/virtualenv@20.26.1...20.26.6) --- updated-dependencies: - dependency-name: virtualenv dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump jinja2 from 3.1.4 to 3.1.5 in /docs (#388) Bumps [jinja2](https://github.com/pallets/jinja) from 3.1.4 to 3.1.5. - [Release notes](https://github.com/pallets/jinja/releases) - [Changelog](https://github.com/pallets/jinja/blob/main/CHANGES.rst) - [Commits](pallets/jinja@3.1.4...3.1.5) --- updated-dependencies: - dependency-name: jinja2 dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: tests Signed-off-by: Frost Ming <[email protected]>
1 parent bb64350 commit 800c829

File tree

6 files changed

+25
-31
lines changed

6 files changed

+25
-31
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ repos:
99
- id: debug-statements
1010

1111
- repo: https://github.com/asottile/pyupgrade
12-
rev: v3.19.0
12+
rev: v3.19.1
1313
hooks:
1414
- id: pyupgrade
1515
args: [--py37-plus]
1616

1717
- repo: https://github.com/astral-sh/ruff-pre-commit
18-
rev: 'v0.7.3'
18+
rev: 'v0.9.1'
1919
hooks:
2020
- id: ruff
2121
args: [--fix, --exit-non-zero-on-fix, --show-fixes]

tests/test_toml_spec_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def untag(value):
7878
elif value["type"] == "array":
7979
return [untag(i) for i in value["value"]]
8080
else:
81-
raise Exception(f'Unsupported type {value["type"]}')
81+
raise Exception(f"Unsupported type {value['type']}")
8282
else:
8383
return {k: untag(v) for k, v in value.items()}
8484

tests/test_toml_tests.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def untag(value):
3838
elif value["type"] == "array":
3939
return [untag(i) for i in value["value"]]
4040
else:
41-
raise Exception(f'Unsupported type {value["type"]}')
41+
raise Exception(f"Unsupported type {value['type']}")
4242
else:
4343
return {k: untag(v) for k, v in value.items()}
4444

@@ -57,7 +57,6 @@ def test_invalid_decode(invalid_decode_case):
5757

5858

5959
def test_invalid_encode(invalid_encode_case):
60-
with pytest.raises((TOMLKitError, UnicodeDecodeError)), open(
61-
invalid_encode_case, encoding="utf-8"
62-
) as f:
63-
load(f)
60+
with open(invalid_encode_case, encoding="utf-8") as f:
61+
with pytest.raises((TOMLKitError, UnicodeDecodeError)):
62+
load(f)

tomlkit/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
__version__ = "0.13.2"
3131
__all__ = [
32+
"TOMLDocument",
3233
"aot",
3334
"array",
3435
"boolean",
@@ -48,12 +49,11 @@
4849
"loads",
4950
"nl",
5051
"parse",
52+
"register_encoder",
5153
"string",
5254
"table",
5355
"time",
54-
"TOMLDocument",
56+
"unregister_encoder",
5557
"value",
5658
"ws",
57-
"register_encoder",
58-
"unregister_encoder",
5959
]

tomlkit/items.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ def _getstate(self, protocol: int = 3) -> tuple:
10831083

10841084

10851085
class _ArrayItemGroup:
1086-
__slots__ = ("value", "indent", "comma", "comment")
1086+
__slots__ = ("comma", "comment", "indent", "value")
10871087

10881088
def __init__(
10891089
self,
@@ -1202,7 +1202,7 @@ def multiline(self, multiline: bool) -> Array:
12021202

12031203
def as_string(self) -> str:
12041204
if not self._multiline or not self._value:
1205-
return f'[{"".join(v.as_string() for v in self._iter_items())}]'
1205+
return f"[{''.join(v.as_string() for v in self._iter_items())}]"
12061206

12071207
s = "[\n"
12081208
s += "".join(
@@ -1260,7 +1260,7 @@ def add_line(
12601260
data_values = []
12611261
for i, el in enumerate(items):
12621262
it = item(el, _parent=self)
1263-
if isinstance(it, Comment) or add_comma and isinstance(el, Whitespace):
1263+
if isinstance(it, Comment) or (add_comma and isinstance(el, Whitespace)):
12641264
raise ValueError(f"item type {type(it)} is not allowed in add_line")
12651265
if not isinstance(it, Whitespace):
12661266
if whitespace:
@@ -1743,7 +1743,7 @@ def as_string(self) -> str:
17431743
v_trivia_trail = v.trivia.trail.replace("\n", "")
17441744
buf += (
17451745
f"{v.trivia.indent}"
1746-
f'{k.as_string() + ("." if k.is_dotted() else "")}'
1746+
f"{k.as_string() + ('.' if k.is_dotted() else '')}"
17471747
f"{k.sep}"
17481748
f"{v.as_string()}"
17491749
f"{v.trivia.comment}"

tomlkit/parser.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def _parse_comment_trail(self, parse_trail: bool = True) -> tuple[str, str, str]
264264
# The comment itself
265265
while not self.end() and not self._current.is_nl():
266266
code = ord(self._current)
267-
if code == CHR_DEL or code <= CTRL_CHAR_LIMIT and code != CTRL_I:
267+
if code == CHR_DEL or (code <= CTRL_CHAR_LIMIT and code != CTRL_I):
268268
raise self.parse_error(InvalidControlChar, code, "comments")
269269

270270
if not self.inc():
@@ -636,10 +636,8 @@ def _parse_inline_table(self) -> InlineTable:
636636
self.inc()
637637
break
638638

639-
if (
640-
trailing_comma is False
641-
or trailing_comma is None
642-
and self._current == ","
639+
if trailing_comma is False or (
640+
trailing_comma is None and self._current == ","
643641
):
644642
# Either the previous key-value pair was not followed by a comma
645643
# or the table has an unexpected leading comma.
@@ -675,10 +673,8 @@ def _parse_number(self, raw: str, trivia: Trivia) -> Item | None:
675673
raw = raw[1:]
676674

677675
if len(raw) > 1 and (
678-
raw.startswith("0")
679-
and not raw.startswith(("0.", "0o", "0x", "0b", "0e"))
680-
or sign
681-
and raw.startswith(".")
676+
(raw.startswith("0") and not raw.startswith(("0.", "0o", "0x", "0b", "0e")))
677+
or (sign and raw.startswith("."))
682678
):
683679
return None
684680

@@ -703,10 +699,8 @@ def _parse_number(self, raw: str, trivia: Trivia) -> Item | None:
703699
if "_" in clean:
704700
return None
705701

706-
if (
707-
clean.endswith(".")
708-
or not clean.startswith("0x")
709-
and clean.split("e", 1)[0].endswith(".")
702+
if clean.endswith(".") or (
703+
not clean.startswith("0x") and clean.split("e", 1)[0].endswith(".")
710704
):
711705
return None
712706

@@ -817,14 +811,15 @@ def _parse_string(self, delim: StringType) -> String:
817811
if (
818812
delim.is_singleline()
819813
and not escaped
820-
and (code == CHR_DEL or code <= CTRL_CHAR_LIMIT and code != CTRL_I)
814+
and (code == CHR_DEL or (code <= CTRL_CHAR_LIMIT and code != CTRL_I))
821815
) or (
822816
delim.is_multiline()
823817
and not escaped
824818
and (
825819
code == CHR_DEL
826-
or code <= CTRL_CHAR_LIMIT
827-
and code not in [CTRL_I, CTRL_J, CTRL_M]
820+
or (
821+
code <= CTRL_CHAR_LIMIT and code not in [CTRL_I, CTRL_J, CTRL_M]
822+
)
828823
)
829824
):
830825
raise self.parse_error(InvalidControlChar, code, "strings")

0 commit comments

Comments
 (0)