From e61a7d1da31223833e0cf92d7ef40b4af8617883 Mon Sep 17 00:00:00 2001 From: HeeJae Chang Date: Mon, 27 Jul 2026 14:37:49 -0700 Subject: [PATCH 1/2] Improve mapping type completeness Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- tomlkit/container.py | 4 ++-- tomlkit/items.py | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tomlkit/container.py b/tomlkit/container.py index 8ff30d9..812bfbd 100644 --- a/tomlkit/container.py +++ b/tomlkit/container.py @@ -32,7 +32,7 @@ _NOT_SET = object() -class Container(_CustomDict): # type: ignore[type-arg] +class Container(_CustomDict[str, Any]): """ A container for items within a TOMLDocument. @@ -1053,7 +1053,7 @@ def _previous_item( return prev[-1] if prev else None -class OutOfOrderTableProxy(_CustomDict): # type: ignore[type-arg] +class OutOfOrderTableProxy(_CustomDict[Any, Any]): @staticmethod def validate( container: Container, diff --git a/tomlkit/items.py b/tomlkit/items.py index 31369b0..f33e6d1 100644 --- a/tomlkit/items.py +++ b/tomlkit/items.py @@ -177,7 +177,7 @@ def item(value: Any, _parent: Item | None = None, _sort_keys: bool = False) -> I v = table - a.append(v) + a.append(v) # pyright: ignore[reportArgumentType] return a elif isinstance(value, str): @@ -455,10 +455,10 @@ def __init__( if original is None: original = ".".join(k.as_string() for k in self._keys) - self.sep = " = " if sep is None else sep + self.sep: str = " = " if sep is None else sep self._original = original self._dotted = False - self.key = ".".join(k.key for k in self._keys) + self.key: str = ".".join(k.key for k in self._keys) def __hash__(self) -> int: return hash(tuple(self._keys)) @@ -1374,7 +1374,7 @@ def __bool__(self) -> bool: return True -class Array(Item, _CustomList): # type: ignore[type-arg] +class Array(Item, _CustomList[Any]): """ An array literal """ @@ -1729,7 +1729,7 @@ def _getstate(self, protocol: int = 3) -> tuple[list[Item], Trivia, bool]: return list(self._iter_items()), self._trivia, self._multiline -class AbstractTable(Item, _CustomDict): # type: ignore[type-arg] +class AbstractTable(Item, _CustomDict[Key | str, Any]): """Common behaviour of both :class:`Table` and :class:`InlineTable`""" def __init__(self, value: container.Container, trivia: Trivia): @@ -2158,7 +2158,7 @@ def _render_dotted(self, key: Key, table: Table) -> list[str]: ``prefix.child = value`` strings, recursing into nested dotted children.""" prefix = f"{key.as_string()}.{key.sep}" - parts = [] + parts: list[str] = [] for k, v in table.value.body: if k is None: continue @@ -2256,7 +2256,7 @@ def from_raw( return cls(type_, decode(value), string_value, Trivia()) -class AoT(Item, _CustomList): # type: ignore[type-arg] +class AoT(Item, _CustomList[Table]): """ An array of table literal """ @@ -2279,7 +2279,7 @@ def unwrap(self) -> list[dict[str, Any]]: if hasattr(t, "unwrap"): unwrapped.append(t.unwrap()) else: - unwrapped.append(t) + unwrapped.append(t) # type: ignore[arg-type] return unwrapped @property @@ -2314,7 +2314,7 @@ def __delitem__(self, key: slice | int) -> None: # type: ignore[override] list.__delitem__(self, key) def insert(self, index: int, value: dict[str, Any]) -> None: # type: ignore[override] - value = item(value, _parent=self) + value = item(value, _parent=self) # pyright: ignore[reportAssignmentType] if not isinstance(value, Table): raise ValueError(f"Unsupported insert value type: {type(value)}") length = len(self) From 116f4c94c4fac88f60a22b4e8b7d2ba849b05539 Mon Sep 17 00:00:00 2001 From: HeeJae Chang Date: Mon, 27 Jul 2026 15:00:52 -0700 Subject: [PATCH 2/2] Restore typing ownership boundaries Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- tomlkit/container.py | 4 ++-- tomlkit/items.py | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tomlkit/container.py b/tomlkit/container.py index 812bfbd..8ff30d9 100644 --- a/tomlkit/container.py +++ b/tomlkit/container.py @@ -32,7 +32,7 @@ _NOT_SET = object() -class Container(_CustomDict[str, Any]): +class Container(_CustomDict): # type: ignore[type-arg] """ A container for items within a TOMLDocument. @@ -1053,7 +1053,7 @@ def _previous_item( return prev[-1] if prev else None -class OutOfOrderTableProxy(_CustomDict[Any, Any]): +class OutOfOrderTableProxy(_CustomDict): # type: ignore[type-arg] @staticmethod def validate( container: Container, diff --git a/tomlkit/items.py b/tomlkit/items.py index f33e6d1..31369b0 100644 --- a/tomlkit/items.py +++ b/tomlkit/items.py @@ -177,7 +177,7 @@ def item(value: Any, _parent: Item | None = None, _sort_keys: bool = False) -> I v = table - a.append(v) # pyright: ignore[reportArgumentType] + a.append(v) return a elif isinstance(value, str): @@ -455,10 +455,10 @@ def __init__( if original is None: original = ".".join(k.as_string() for k in self._keys) - self.sep: str = " = " if sep is None else sep + self.sep = " = " if sep is None else sep self._original = original self._dotted = False - self.key: str = ".".join(k.key for k in self._keys) + self.key = ".".join(k.key for k in self._keys) def __hash__(self) -> int: return hash(tuple(self._keys)) @@ -1374,7 +1374,7 @@ def __bool__(self) -> bool: return True -class Array(Item, _CustomList[Any]): +class Array(Item, _CustomList): # type: ignore[type-arg] """ An array literal """ @@ -1729,7 +1729,7 @@ def _getstate(self, protocol: int = 3) -> tuple[list[Item], Trivia, bool]: return list(self._iter_items()), self._trivia, self._multiline -class AbstractTable(Item, _CustomDict[Key | str, Any]): +class AbstractTable(Item, _CustomDict): # type: ignore[type-arg] """Common behaviour of both :class:`Table` and :class:`InlineTable`""" def __init__(self, value: container.Container, trivia: Trivia): @@ -2158,7 +2158,7 @@ def _render_dotted(self, key: Key, table: Table) -> list[str]: ``prefix.child = value`` strings, recursing into nested dotted children.""" prefix = f"{key.as_string()}.{key.sep}" - parts: list[str] = [] + parts = [] for k, v in table.value.body: if k is None: continue @@ -2256,7 +2256,7 @@ def from_raw( return cls(type_, decode(value), string_value, Trivia()) -class AoT(Item, _CustomList[Table]): +class AoT(Item, _CustomList): # type: ignore[type-arg] """ An array of table literal """ @@ -2279,7 +2279,7 @@ def unwrap(self) -> list[dict[str, Any]]: if hasattr(t, "unwrap"): unwrapped.append(t.unwrap()) else: - unwrapped.append(t) # type: ignore[arg-type] + unwrapped.append(t) return unwrapped @property @@ -2314,7 +2314,7 @@ def __delitem__(self, key: slice | int) -> None: # type: ignore[override] list.__delitem__(self, key) def insert(self, index: int, value: dict[str, Any]) -> None: # type: ignore[override] - value = item(value, _parent=self) # pyright: ignore[reportAssignmentType] + value = item(value, _parent=self) if not isinstance(value, Table): raise ValueError(f"Unsupported insert value type: {type(value)}") length = len(self)