Skip to content

Commit 4e9df46

Browse files
committed
test: drop wrap_method coverage, stop asserting Array type on __add__
dimbleby and davidpavlovschi both flagged the same thing from two angles: wrap_method has been dead since #460, so testing it just locks in code nobody calls. Removed it from _types.py along with the Callable/Concatenate/ParamSpec plumbing that existed only for its signature, and dropped the corresponding tests. Also backed off the __add__ test's `assert not isinstance(result, Array)`. That was asserting an implementation detail the PR description itself called out as possibly unintended, and davidpavlovschi's right that a coverage PR shouldn't be the thing that decides whether __add__ is supposed to return a plain list or a wrapped Array. The test now just checks the combined values.
1 parent fb63867 commit 4e9df46

2 files changed

Lines changed: 1 addition & 54 deletions

File tree

‎tests/test_types.py‎

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
from typing import Any
2-
31
import tomlkit
42

5-
from tomlkit._types import wrap_method
63
from tomlkit.items import Array
74
from tomlkit.items import Table
85

96

10-
def test_custom_list_add_returns_plain_list_with_combined_items() -> None:
7+
def test_custom_list_add_returns_combined_items() -> None:
118
arr = tomlkit.array()
129
arr.extend([1, 2, 3])
1310

1411
result = arr + [4, 5] # noqa: RUF005 (exercising __add__ itself)
1512

1613
assert result == [1, 2, 3, 4, 5]
17-
assert not isinstance(result, Array)
1814

1915

2016
def test_custom_list_iadd_mutates_in_place_and_keeps_wrapper_type() -> None:
@@ -50,34 +46,3 @@ def test_custom_dict_ior_mutates_in_place() -> None:
5046

5147
assert dict(table) == {"x": 1, "y": 2}
5248
assert id(table) == original_id
53-
54-
55-
class _Wrapped:
56-
def __init__(self, value: int) -> None:
57-
self.value = value
58-
59-
def _new(self, value: int) -> "_Wrapped":
60-
return _Wrapped(value)
61-
62-
63-
def test_wrap_method_wraps_result_via_new() -> None:
64-
def raw_add(self: _Wrapped, other: int) -> int:
65-
return self.value + other
66-
67-
wrapped_add = wrap_method(raw_add)
68-
wrapped = _Wrapped(5)
69-
70-
result = wrapped_add(wrapped, 3)
71-
72-
assert isinstance(result, _Wrapped)
73-
assert result.value == 8
74-
75-
76-
def test_wrap_method_passes_through_not_implemented() -> None:
77-
def raw_not_implemented(self: _Wrapped, other: int) -> Any:
78-
return NotImplemented
79-
80-
wrapped_method = wrap_method(raw_not_implemented)
81-
wrapped = _Wrapped(5)
82-
83-
assert wrapped_method(wrapped, 3) is NotImplemented

‎tomlkit/_types.py‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"_CustomFloat",
1313
"_CustomInt",
1414
"_CustomList",
15-
"wrap_method",
1615
]
1716

1817
if TYPE_CHECKING: # pragma: no cover
@@ -31,13 +30,8 @@
3130
from builtins import float as _CustomFloat
3231
from builtins import int as _CustomInt
3332
from builtins import list as _CustomList
34-
from typing import Callable
35-
from typing import Concatenate
36-
from typing import ParamSpec
3733
from typing import Protocol
3834

39-
P = ParamSpec("P")
40-
4135
class WrapperType(Protocol):
4236
def _new(self: WT, value: Any) -> WT: ...
4337

@@ -76,15 +70,3 @@ class _CustomInt(Integral, int):
7670

7771
class _CustomFloat(Real, float):
7872
"""Adds Real mixin while pretending to be a builtin float"""
79-
80-
81-
def wrap_method(
82-
original_method: Callable[Concatenate[WT, P], Any],
83-
) -> Callable[Concatenate[WT, P], Any]:
84-
def wrapper(self: WT, /, *args: P.args, **kwargs: P.kwargs) -> Any:
85-
result = original_method(self, *args, **kwargs)
86-
if result is NotImplemented:
87-
return result
88-
return self._new(result)
89-
90-
return wrapper

0 commit comments

Comments
 (0)