Skip to content

Commit 7aa5bde

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent df1941a commit 7aa5bde

8 files changed

Lines changed: 21 additions & 20 deletions

File tree

‎tests/test_api.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
import json
33
import os
44

5+
from collections.abc import Callable
56
from datetime import date
67
from datetime import datetime
78
from datetime import time
89
from types import MappingProxyType
910
from typing import Any
10-
from typing import Callable
1111

1212
import pytest
1313

‎tests/test_toml_tests.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import json
22
import os
33

4+
from collections.abc import Callable
45
from typing import Any
5-
from typing import Callable
66

77
import pytest
88

‎tests/test_utils.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from datetime import time
44
from datetime import timedelta as td
55
from datetime import timezone as tz
6-
from typing import Union
76

87
import pytest
98

@@ -35,18 +34,18 @@
3534
),
3635
],
3736
)
38-
def test_parse_rfc3339_datetime(string: str, expected: Union[dt, date, time]) -> None:
37+
def test_parse_rfc3339_datetime(string: str, expected: dt | date | time) -> None:
3938
assert parse_rfc3339(string) == expected
4039

4140

4241
@pytest.mark.parametrize("string, expected", [("1979-05-27", date(1979, 5, 27))])
43-
def test_parse_rfc3339_date(string: str, expected: Union[dt, date, time]) -> None:
42+
def test_parse_rfc3339_date(string: str, expected: dt | date | time) -> None:
4443
assert parse_rfc3339(string) == expected
4544

4645

4746
@pytest.mark.parametrize(
4847
"string, expected",
4948
[("12:34:56", time(12, 34, 56)), ("12:34:56.123456", time(12, 34, 56, 123456))],
5049
)
51-
def test_parse_rfc3339_time(string: str, expected: Union[dt, date, time]) -> None:
50+
def test_parse_rfc3339_time(string: str, expected: dt | date | time) -> None:
5251
assert parse_rfc3339(string) == expected

‎tomlkit/_types.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from typing import Any
55
from typing import TypeVar
66

7+
from typing_extensions import Self
8+
79

810
WT = TypeVar("WT", bound="WrapperType")
911

@@ -31,15 +33,15 @@
3133
from builtins import float as _CustomFloat
3234
from builtins import int as _CustomInt
3335
from builtins import list as _CustomList
34-
from typing import Callable
36+
from collections.abc import Callable
3537
from typing import Concatenate
3638
from typing import ParamSpec
3739
from typing import Protocol
3840

3941
P = ParamSpec("P")
4042

4143
class WrapperType(Protocol):
42-
def _new(self: WT, value: Any) -> WT: ...
44+
def _new(self, value: Any) -> Self: ...
4345

4446
else:
4547
from collections.abc import MutableMapping

‎tomlkit/_utils.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,4 @@ def merge_dicts(d1: dict[str, Any], d2: dict[str, Any]) -> None:
159159
if k in d1 and isinstance(d1[k], dict) and isinstance(v, Mapping):
160160
merge_dicts(d1[k], dict(v))
161161
else:
162-
d1[k] = d2[k]
162+
d1[k] = v

‎tomlkit/container.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ def _handle_dotted_key(self, key: Key, value: Item) -> None:
148148
current.append(last, value)
149149

150150
self.append(name, table)
151-
return
152151

153152
def _get_last_index_before_table(self) -> int:
154153
last_index = -1
@@ -1278,7 +1277,7 @@ def _equal_with_nan(left: Any, right: Any) -> bool:
12781277
if isinstance(left, list) and isinstance(right, list):
12791278
if len(left) != len(right):
12801279
return False
1281-
return all(_equal_with_nan(l, r) for l, r in zip(left, right)) # noqa: B905, E741
1280+
return all(_equal_with_nan(l, r) for l, r in zip(left, right)) # noqa: B905
12821281

12831282
if isinstance(left, float) and isinstance(right, float):
12841283
if math.isnan(left) and math.isnan(right):

‎tomlkit/items.py‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from typing import TypeVar
2323
from typing import overload
2424

25+
from typing_extensions import Self
26+
2527
from tomlkit._compat import PY38
2628
from tomlkit._compat import decode
2729
from tomlkit._types import _CustomDict
@@ -437,7 +439,7 @@ def is_bare(self) -> bool:
437439
def __hash__(self) -> int:
438440
return hash(self.key)
439441

440-
def __eq__(self, other: Any) -> bool:
442+
def __eq__(self, other: object) -> bool:
441443
if isinstance(other, Key):
442444
return isinstance(other, SingleKey) and self.key == other.key
443445

@@ -1599,8 +1601,7 @@ def insert(self, pos: int, value: Any) -> None: # type: ignore[override]
15991601
list.insert(self, pos, it)
16001602
if pos < 0:
16011603
pos += length
1602-
if pos < 0:
1603-
pos = 0
1604+
pos = max(pos, 0)
16041605

16051606
idx = 0 # insert position of the self._value list
16061607
default_indent = " "
@@ -1758,7 +1759,7 @@ def append(self: AT, key: None, value: Comment | Whitespace) -> AT: ...
17581759
@overload
17591760
def append(self: AT, key: Key | str, value: Any) -> AT: ...
17601761

1761-
def append(self: AT, key: Key | str | None, value: Any) -> AT:
1762+
def append(self, key: Key | str | None, value: Any) -> Self:
17621763
raise NotImplementedError
17631764

17641765
@overload
@@ -1768,8 +1769,8 @@ def add(self: AT, key: Comment | Whitespace) -> AT: ...
17681769
def add(self: AT, key: Key | str, value: Any = ...) -> AT: ...
17691770

17701771
def add(
1771-
self: AT, key: Key | str | Comment | Whitespace, value: Any | None = None
1772-
) -> AT:
1772+
self, key: Key | str | Comment | Whitespace, value: Any | None = None
1773+
) -> Self:
17731774
if value is None:
17741775
if not isinstance(key, (Comment, Whitespace)):
17751776
msg = "Non comment/whitespace items must have an associated key"
@@ -1782,7 +1783,7 @@ def add(
17821783

17831784
return self.append(key, value)
17841785

1785-
def remove(self: AT, key: Key | str) -> AT:
1786+
def remove(self, key: Key | str) -> Self:
17861787
self._value.remove(key)
17871788

17881789
if isinstance(key, Key):
@@ -1803,7 +1804,7 @@ def setdefault(self, key: Key | str, default: Any) -> Any: # type: ignore[overr
18031804
def __str__(self) -> str:
18041805
return str(self.value)
18051806

1806-
def copy(self: AT) -> AT:
1807+
def copy(self) -> Self:
18071808
return copy.copy(self)
18081809

18091810
def __repr__(self) -> str:

‎tomlkit/parser.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import re
55
import string
66

7+
from collections.abc import Callable
78
from typing import Any
8-
from typing import Callable
99

1010
from tomlkit._compat import decode
1111
from tomlkit._utils import RFC_3339_LOOSE

0 commit comments

Comments
 (0)