Skip to content

Commit 8ea7f6c

Browse files
committed
ruff format
1 parent c54a641 commit 8ea7f6c

File tree

7 files changed

+88
-32
lines changed

7 files changed

+88
-32
lines changed

tests/test_api.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def json_serial(obj: Any) -> str:
6565
"table_names",
6666
],
6767
)
68-
def test_parse_can_parse_valid_toml_files(example: Callable[[str], str], example_name: str) -> None:
68+
def test_parse_can_parse_valid_toml_files(
69+
example: Callable[[str], str], example_name: str
70+
) -> None:
6971
assert isinstance(parse(example(example_name)), TOMLDocument)
7072
assert isinstance(loads(example(example_name)), TOMLDocument)
7173

@@ -145,7 +147,9 @@ def test_parse_raises_errors_for_invalid_toml_files(
145147
"table_names",
146148
],
147149
)
148-
def test_original_string_and_dumped_string_are_equal(example: Callable[[str], str], example_name: str) -> None:
150+
def test_original_string_and_dumped_string_are_equal(
151+
example: Callable[[str], str], example_name: str
152+
) -> None:
149153
content = example(example_name)
150154
parsed = parse(content)
151155

@@ -463,7 +467,9 @@ def test_create_string(kwargs: dict[str, Any], example: str, expected: str) -> N
463467
({"multiline": True, "literal": True}, "My'''String"),
464468
],
465469
)
466-
def test_create_string_with_invalid_characters(kwargs: dict[str, Any], example: str) -> None:
470+
def test_create_string_with_invalid_characters(
471+
kwargs: dict[str, Any], example: str
472+
) -> None:
467473
with pytest.raises(InvalidStringError):
468474
tomlkit.string(example, **kwargs)
469475

tests/test_build.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ def test_build_example(example: Callable[[str], str]) -> None:
4040

4141
servers = table()
4242
servers.add(nl())
43-
c = comment(
44-
"You can indent as you please. Tabs or spaces. TOML don't care."
45-
)
43+
c = comment("You can indent as you please. Tabs or spaces. TOML don't care.")
4644
c.indent(2)
4745
c.trivia.trail = ""
4846
servers.add(c)

tests/test_items.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ def test_inf_and_nan_are_supported(example: Callable[[str], str]) -> None:
269269
assert math.isnan(doc["sf6"])
270270

271271

272-
def test_hex_octal_and_bin_integers_are_supported(example: Callable[[str], str]) -> None:
272+
def test_hex_octal_and_bin_integers_are_supported(
273+
example: Callable[[str], str],
274+
) -> None:
273275
content = example("0.5.0")
274276
doc = parse(content)
275277

@@ -999,7 +1001,9 @@ def test_custom_encoders_with_parent_and_sort_keys() -> None:
9991001
sort_keys_captured = None
10001002

10011003
@api.register_encoder
1002-
def encode_decimal_with_context(obj: Any, _parent: Item | None = None, _sort_keys: bool = False) -> Item:
1004+
def encode_decimal_with_context(
1005+
obj: Any, _parent: Item | None = None, _sort_keys: bool = False
1006+
) -> Item:
10031007
nonlocal parent_captured, sort_keys_captured
10041008
if isinstance(obj, decimal.Decimal):
10051009
parent_captured = _parent
@@ -1079,7 +1083,9 @@ def __init__(self, data: dict[str, Any]) -> None:
10791083
self.data = data
10801084

10811085
@api.register_encoder
1082-
def encode_custom_dict(obj: Any, _parent: Item | None = None, _sort_keys: bool = False) -> Item:
1086+
def encode_custom_dict(
1087+
obj: Any, _parent: Item | None = None, _sort_keys: bool = False
1088+
) -> Item:
10831089
if isinstance(obj, CustomDict):
10841090
# Create a table and use item() to convert nested values
10851091
table = api.table()

tests/test_parser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
from tomlkit.parser import Parser
88

99

10-
def test_parser_should_raise_an_internal_error_if_parsing_wrong_type_of_string() -> None:
10+
def test_parser_should_raise_an_internal_error_if_parsing_wrong_type_of_string() -> (
11+
None
12+
):
1113
parser = Parser('"foo"')
1214

1315
with pytest.raises(InternalParserError) as e:

tests/test_toml_document.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ def test_toml_document_with_dotted_keys(example: Callable[[str], str]) -> None:
191191
assert doc["a"]["b"]["d"] == 2
192192

193193

194-
def test_toml_document_super_table_with_different_sub_sections(example: Callable[[str], str]) -> None:
194+
def test_toml_document_super_table_with_different_sub_sections(
195+
example: Callable[[str], str],
196+
) -> None:
195197
content = example("pyproject")
196198

197199
doc = parse(content)
@@ -338,7 +340,9 @@ def test_inserting_after_deletion() -> None:
338340
assert expected == doc.as_string()
339341

340342

341-
def test_toml_document_with_dotted_keys_inside_table(example: Callable[[str], str]) -> None:
343+
def test_toml_document_with_dotted_keys_inside_table(
344+
example: Callable[[str], str],
345+
) -> None:
342346
content = example("0.5.0")
343347

344348
doc = parse(content)
@@ -351,7 +355,9 @@ def test_toml_document_with_dotted_keys_inside_table(example: Callable[[str], st
351355
assert t["a"]["c"] == 3
352356

353357

354-
def test_toml_document_with_super_aot_after_super_table(example: Callable[[str], str]) -> None:
358+
def test_toml_document_with_super_aot_after_super_table(
359+
example: Callable[[str], str],
360+
) -> None:
355361
content = example("pyproject")
356362

357363
doc = parse(content)

tests/test_toml_tests.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,14 @@ def _load_case_list() -> list[str]:
5656
return [line.strip() for line in f if line.strip()]
5757

5858

59-
def _build_cases() -> tuple[list[dict[str, str]], list[str], list[dict[str, str]], list[str], list[str], list[str]]:
59+
def _build_cases() -> tuple[
60+
list[dict[str, str]],
61+
list[str],
62+
list[dict[str, str]],
63+
list[str],
64+
list[str],
65+
list[str],
66+
]:
6067
valid_cases = []
6168
valid_ids = []
6269
invalid_decode_cases = []

tomlkit/items.py

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def item(value: str, _parent: Item | None = ..., _sort_keys: bool = ...) -> Stri
6565

6666

6767
@overload
68-
def item(value: datetime, _parent: Item | None = ..., _sort_keys: bool = ...) -> DateTime: ... # type: ignore[overload-overlap]
68+
def item(
69+
value: datetime, _parent: Item | None = ..., _sort_keys: bool = ...
70+
) -> DateTime: ... # type: ignore[overload-overlap]
6971

7072

7173
@overload
@@ -89,11 +91,15 @@ def item(
8991

9092

9193
@overload
92-
def item(value: dict[str, Any], _parent: Array = ..., _sort_keys: bool = ...) -> InlineTable: ...
94+
def item(
95+
value: dict[str, Any], _parent: Array = ..., _sort_keys: bool = ...
96+
) -> InlineTable: ...
9397

9498

9599
@overload
96-
def item(value: dict[str, Any], _parent: Item | None = ..., _sort_keys: bool = ...) -> Table: ...
100+
def item(
101+
value: dict[str, Any], _parent: Item | None = ..., _sort_keys: bool = ...
102+
) -> Table: ...
97103

98104

99105
@overload
@@ -714,7 +720,9 @@ def __pos__(self) -> Integer:
714720
return self._new(int.__pos__(self))
715721

716722
def __pow__(self, other: int, mod: int | None = None) -> Integer: # type: ignore[override]
717-
result = int.__pow__(self, other) if mod is None else int.__pow__(self, other, mod)
723+
result = (
724+
int.__pow__(self, other) if mod is None else int.__pow__(self, other, mod)
725+
)
718726
return self._new(result)
719727

720728
def __radd__(self, other: object) -> Integer:
@@ -763,7 +771,9 @@ def __round__(self, ndigits: int = 0) -> Integer: # type: ignore[override]
763771
return self._new(int.__round__(self, ndigits))
764772

765773
def __rpow__(self, other: int, mod: int | None = None) -> Integer: # type: ignore[misc]
766-
result = int.__rpow__(self, other) if mod is None else int.__rpow__(self, other, mod)
774+
result = (
775+
int.__rpow__(self, other) if mod is None else int.__rpow__(self, other, mod)
776+
)
767777
return self._new(result)
768778

769779
def __rrshift__(self, other: object) -> Integer:
@@ -1162,7 +1172,9 @@ def _new(self, result: datetime) -> DateTime:
11621172
raw,
11631173
)
11641174

1165-
def _getstate(self, protocol: int = 3) -> tuple[int, int, int, int, int, int, int, tzinfo | None, Trivia, str]:
1175+
def _getstate(
1176+
self, protocol: int = 3
1177+
) -> tuple[int, int, int, int, int, int, int, tzinfo | None, Trivia, str]:
11661178
return (
11671179
self.year,
11681180
self.month,
@@ -1182,7 +1194,14 @@ class Date(Item, date):
11821194
A date literal.
11831195
"""
11841196

1185-
def __new__(cls, year: int, month: int, day: int, trivia: Trivia | None = None, raw: str = "") -> Date:
1197+
def __new__(
1198+
cls,
1199+
year: int,
1200+
month: int,
1201+
day: int,
1202+
trivia: Trivia | None = None,
1203+
raw: str = "",
1204+
) -> Date:
11861205
return date.__new__(cls, year, month, day)
11871206

11881207
def __init__(
@@ -1311,7 +1330,9 @@ def _new(self, result: time) -> Time:
13111330
raw,
13121331
)
13131332

1314-
def _getstate(self, protocol: int = 3) -> tuple[int, int, int, int, tzinfo | None, Trivia, str]:
1333+
def _getstate(
1334+
self, protocol: int = 3
1335+
) -> tuple[int, int, int, int, tzinfo | None, Trivia, str]:
13151336
return (
13161337
self.hour,
13171338
self.minute,
@@ -1339,7 +1360,11 @@ def __init__(
13391360
self.comment = comment
13401361

13411362
def __iter__(self) -> Iterator[Item]:
1342-
return (x for x in (self.indent, self.value, self.comma, self.comment) if x is not None)
1363+
return (
1364+
x
1365+
for x in (self.indent, self.value, self.comma, self.comment)
1366+
if x is not None
1367+
)
13431368

13441369
def __repr__(self) -> str:
13451370
return repr(tuple(self))
@@ -1594,10 +1619,7 @@ def insert(self, pos: int, value: Any) -> None: # type: ignore[override]
15941619
# The last item is a pure whitespace(\n ), insert before it
15951620
idx -= 1
15961621
_indent = self._value[idx].indent
1597-
if (
1598-
_indent is not None
1599-
and "\n" in _indent.s
1600-
):
1622+
if _indent is not None and "\n" in _indent.s:
16011623
default_indent = "\n "
16021624
indent: Whitespace | None = None
16031625
comma: Whitespace | None = Whitespace(",") if pos < length else None
@@ -1741,7 +1763,9 @@ def add(self: AT, key: Comment | Whitespace) -> AT: ...
17411763
@overload
17421764
def add(self: AT, key: Key | str, value: Any = ...) -> AT: ...
17431765

1744-
def add(self: AT, key: Key | str | Comment | Whitespace, value: Any | None = None) -> AT:
1766+
def add(
1767+
self: AT, key: Key | str | Comment | Whitespace, value: Any | None = None
1768+
) -> AT:
17451769
if value is None:
17461770
if not isinstance(key, (Comment, Whitespace)):
17471771
msg = "Non comment/whitespace items must have an associated key"
@@ -1772,7 +1796,8 @@ def setdefault(self, key: Key | str, default: Any) -> Any: # type: ignore[overr
17721796
super().setdefault(key, default)
17731797
return self[key]
17741798

1775-
def __str__(self) -> str: return str(self.value)
1799+
def __str__(self) -> str:
1800+
return str(self.value)
17761801

17771802
def copy(self: AT) -> AT:
17781803
return copy.copy(self)
@@ -1956,7 +1981,9 @@ def invalidate_display_name(self) -> None:
19561981
if hasattr(child, "invalidate_display_name"):
19571982
child.invalidate_display_name()
19581983

1959-
def _getstate(self, protocol: int = 3) -> tuple[container.Container, Trivia, bool, bool | None, str | None, str | None]:
1984+
def _getstate(
1985+
self, protocol: int = 3
1986+
) -> tuple[container.Container, Trivia, bool, bool | None, str | None, str | None]:
19601987
return (
19611988
self._value,
19621989
self._trivia,
@@ -2090,7 +2117,9 @@ class String(str, Item): # type: ignore[misc]
20902117
A string literal.
20912118
"""
20922119

2093-
def __new__(cls, t: StringType, value: str, original: str, trivia: Trivia) -> String:
2120+
def __new__(
2121+
cls, t: StringType, value: str, original: str, trivia: Trivia
2122+
) -> String:
20942123
return super().__new__(cls, value)
20952124

20962125
def __init__(self, t: StringType, _: str, original: str, trivia: Trivia) -> None:
@@ -2130,7 +2159,9 @@ def _getstate(self, protocol: int = 3) -> tuple[StringType, str, str, Trivia]:
21302159
return self._t, str(self), self._original, self._trivia
21312160

21322161
@classmethod
2133-
def from_raw(cls, value: str, type_: StringType = StringType.SLB, escape: bool = True) -> String:
2162+
def from_raw(
2163+
cls, value: str, type_: StringType = StringType.SLB, escape: bool = True
2164+
) -> String:
21342165
value = decode(value)
21352166

21362167
invalid = type_.invalid_sequences

0 commit comments

Comments
 (0)