Skip to content

Commit 6bbb9e9

Browse files
committed
fix: throw type error instead of casting to str
1 parent 8fa9365 commit 6bbb9e9

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

tests/test_toml_document.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,4 +1191,5 @@ def test_overwrite_out_of_order_table_key():
11911191

11921192

11931193
def test_set_default_int():
1194-
TOMLDocument().setdefault(4, 5)
1194+
with pytest.raises(TypeError):
1195+
TOMLDocument().setdefault(4, 5)

tomlkit/items.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,14 +375,13 @@ class SingleKey(Key):
375375

376376
def __init__(
377377
self,
378-
k: str | int,
378+
k: str,
379379
t: KeyType | None = None,
380380
sep: str | None = None,
381381
original: str | None = None,
382382
) -> None:
383-
# keys are allowed to be ints but should be interpreted as strings
384383
if not isinstance(k, str):
385-
k = str(k)
384+
raise TypeError("Keys must be strings")
386385

387386
if t is None:
388387
if not k or any(

0 commit comments

Comments
 (0)