Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#386)
Browse files Browse the repository at this point in the history
* [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]>
  • Loading branch information
pre-commit-ci[bot] authored Jan 14, 2025
1 parent bb64350 commit 800c829
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ repos:
- id: debug-statements

- repo: https://github.com/asottile/pyupgrade
rev: v3.19.0
rev: v3.19.1
hooks:
- id: pyupgrade
args: [--py37-plus]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.7.3'
rev: 'v0.9.1'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_toml_spec_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def untag(value):
elif value["type"] == "array":
return [untag(i) for i in value["value"]]
else:
raise Exception(f'Unsupported type {value["type"]}')
raise Exception(f"Unsupported type {value['type']}")
else:
return {k: untag(v) for k, v in value.items()}

Expand Down
9 changes: 4 additions & 5 deletions tests/test_toml_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def untag(value):
elif value["type"] == "array":
return [untag(i) for i in value["value"]]
else:
raise Exception(f'Unsupported type {value["type"]}')
raise Exception(f"Unsupported type {value['type']}")
else:
return {k: untag(v) for k, v in value.items()}

Expand All @@ -57,7 +57,6 @@ 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:
load(f)
with open(invalid_encode_case, encoding="utf-8") as f:
with pytest.raises((TOMLKitError, UnicodeDecodeError)):
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",
]
8 changes: 4 additions & 4 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 @@ -1202,7 +1202,7 @@ def multiline(self, multiline: bool) -> Array:

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

s = "[\n"
s += "".join(
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 Expand Up @@ -1743,7 +1743,7 @@ def as_string(self) -> str:
v_trivia_trail = v.trivia.trail.replace("\n", "")
buf += (
f"{v.trivia.indent}"
f'{k.as_string() + ("." if k.is_dotted() else "")}'
f"{k.as_string() + ('.' if k.is_dotted() else '')}"
f"{k.sep}"
f"{v.as_string()}"
f"{v.trivia.comment}"
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 800c829

Please sign in to comment.