diff --git a/news/6024.vendor.rst b/news/6024.vendor.rst new file mode 100644 index 00000000..0aec2abf --- /dev/null +++ b/news/6024.vendor.rst @@ -0,0 +1 @@ +Update vendored tomlkit to ``0.12.3`` diff --git a/pipenv/vendor/tomlkit/__init__.py b/pipenv/vendor/tomlkit/__init__.py index c4534b96..51464f6c 100644 --- a/pipenv/vendor/tomlkit/__init__.py +++ b/pipenv/vendor/tomlkit/__init__.py @@ -27,7 +27,7 @@ from pipenv.vendor.tomlkit.api import value from pipenv.vendor.tomlkit.api import ws -__version__ = "0.12.1" +__version__ = "0.12.3" __all__ = [ "aot", "array", diff --git a/pipenv/vendor/tomlkit/container.py b/pipenv/vendor/tomlkit/container.py index b14d4fc8..6b2e4b96 100644 --- a/pipenv/vendor/tomlkit/container.py +++ b/pipenv/vendor/tomlkit/container.py @@ -44,6 +44,7 @@ class Container(_CustomDict): return self._body def unwrap(self) -> dict[str, Any]: + """Returns as pure python object (ppo)""" unwrapped = {} for k, v in self.items(): if k is None: @@ -64,6 +65,7 @@ class Container(_CustomDict): @property def value(self) -> dict[str, Any]: + """The wrapped dict value""" d = {} for k, v in self._body: if k is None: @@ -145,7 +147,19 @@ class Container(_CustomDict): last_index = i return last_index + 1 - def append(self, key: Key | str | None, item: Item) -> Container: + def _validate_out_of_order_table(self, key: SingleKey | None = None) -> None: + if key is None: + for k in self._map: + assert k is not None + self._validate_out_of_order_table(k) + return + if key not in self._map or not isinstance(self._map[key], tuple): + return + OutOfOrderTableProxy(self, self._map[key]) + + def append( + self, key: Key | str | None, item: Item, validate: bool = True + ) -> Container: """Similar to :meth:`add` but both key and value must be given.""" if not isinstance(key, Key) and key is not None: key = SingleKey(key) @@ -227,8 +241,8 @@ class Container(_CustomDict): else: self._raw_append(key, item) - # Building a temporary proxy to check for errors - OutOfOrderTableProxy(self, self._map[key]) + if validate: + self._validate_out_of_order_table(key) return self @@ -286,7 +300,7 @@ class Container(_CustomDict): self._raw_append(key, item) return self - def _raw_append(self, key: Key, item: Item) -> None: + def _raw_append(self, key: Key | None, item: Item) -> None: if key in self._map: current_idx = self._map[key] if not isinstance(current_idx, tuple): @@ -297,7 +311,7 @@ class Container(_CustomDict): raise KeyAlreadyPresent(key) self._map[key] = current_idx + (len(self._body),) - else: + elif key is not None: self._map[key] = len(self._body) self._body.append((key, item)) @@ -605,21 +619,8 @@ class Container(_CustomDict): # Dictionary methods def __getitem__(self, key: Key | str) -> Item | Container: - if not isinstance(key, Key): - key = SingleKey(key) - - idx = self._map.get(key) - if idx is None: - raise NonExistentKey(key) - - if isinstance(idx, tuple): - # The item we are getting is an out of order table - # so we need a proxy to retrieve the proper objects - # from the parent container - return OutOfOrderTableProxy(self, idx) - - item = self._body[idx][1] - if item.is_boolean(): + item = self.item(key) + if isinstance(item, Item) and item.is_boolean(): return item.value return item @@ -700,12 +701,18 @@ class Container(_CustomDict): if isinstance(value, Table): # Insert a cosmetic new line for tables if: # - it does not have it yet OR is not followed by one - # - it is not the last item + # - it is not the last item, or + # - The table being replaced has a newline last, _ = self._previous_item_with_index() idx = last if idx < 0 else idx has_ws = ends_with_whitespace(value) + replace_has_ws = ( + isinstance(v, Table) + and v.value.body + and isinstance(v.value.body[-1][1], Whitespace) + ) next_ws = idx < last and isinstance(self._body[idx + 1][1], Whitespace) - if idx < last and not (next_ws or has_ws): + if (idx < last or replace_has_ws) and not (next_ws or has_ws): value.append(None, Whitespace("\n")) dict.__setitem__(self, new_key.key, value.value) @@ -792,11 +799,13 @@ class OutOfOrderTableProxy(_CustomDict): self._tables.append(item) table_idx = len(self._tables) - 1 for k, v in item.value.body: - self._internal_container.append(k, v) + self._internal_container.append(k, v, validate=False) self._tables_map[k] = table_idx if k is not None: dict.__setitem__(self, k.key, v) + self._internal_container._validate_out_of_order_table() + def unwrap(self) -> str: return self._internal_container.unwrap() diff --git a/pipenv/vendor/tomlkit/items.py b/pipenv/vendor/tomlkit/items.py index b4e59042..0f277ea4 100644 --- a/pipenv/vendor/tomlkit/items.py +++ b/pipenv/vendor/tomlkit/items.py @@ -667,12 +667,22 @@ class Integer(Item, _CustomInt): __rpow__ = wrap_method(int.__rpow__) __rrshift__ = wrap_method(int.__rrshift__) __rshift__ = wrap_method(int.__rshift__) - __rtruediv__ = wrap_method(int.__rtruediv__) __rxor__ = wrap_method(int.__rxor__) - __truediv__ = wrap_method(int.__truediv__) __trunc__ = wrap_method(int.__trunc__) __xor__ = wrap_method(int.__xor__) + def __rtruediv__(self, other): + result = int.__rtruediv__(self, other) + if result is NotImplemented: + return result + return Float._new(self, result) + + def __truediv__(self, other): + result = int.__truediv__(self, other) + if result is NotImplemented: + return result + return Float._new(self, result) + class Float(Item, _CustomFloat): """ @@ -1607,7 +1617,7 @@ class Table(AbstractTable): if not isinstance(_item, Item): _item = item(_item) - self._value.append(key, _item) + self._value.append(key, _item, validate=False) if isinstance(key, Key): key = next(iter(key)).key @@ -1655,6 +1665,7 @@ class Table(AbstractTable): return self def invalidate_display_name(self): + """Call ``invalidate_display_name`` on the contained tables""" self.display_name = None for child in self.values(): @@ -1935,7 +1946,7 @@ class Null(Item): """ def __init__(self) -> None: - pass + super().__init__(Trivia(trail="")) def unwrap(self) -> None: return None diff --git a/pipenv/vendor/tomlkit/parser.py b/pipenv/vendor/tomlkit/parser.py index ba825235..3a559d92 100644 --- a/pipenv/vendor/tomlkit/parser.py +++ b/pipenv/vendor/tomlkit/parser.py @@ -1030,7 +1030,7 @@ class Parser: InternalParserError, "_parse_item() returned None on a non-bracket character.", ) - + table.value._validate_out_of_order_table() if isinstance(result, Null): result = table diff --git a/pipenv/vendor/vendor.txt b/pipenv/vendor/vendor.txt index d755a6df..9b0c801d 100644 --- a/pipenv/vendor/vendor.txt +++ b/pipenv/vendor/vendor.txt @@ -13,4 +13,4 @@ pythonfinder==2.0.6 ruamel.yaml==0.17.39 shellingham==1.5.3 tomli==2.0.1 -tomlkit==0.12.1 +tomlkit==0.12.3