Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/6024.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update vendored tomlkit to ``0.12.3``
2 changes: 1 addition & 1 deletion pipenv/vendor/tomlkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from pipenv.vendor.tomlkit.api import ws


__version__ = "0.12.1"
__version__ = "0.12.3"
__all__ = [
"aot",
"array",
Expand Down
55 changes: 32 additions & 23 deletions pipenv/vendor/tomlkit/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def body(self) -> list[tuple[Key | None, Item]]:
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:
Expand All @@ -64,6 +65,7 @@ def unwrap(self) -> dict[str, Any]:

@property
def value(self) -> dict[str, Any]:
"""The wrapped dict value"""
d = {}
for k, v in self._body:
if k is None:
Expand Down Expand Up @@ -145,7 +147,19 @@ def _get_last_index_before_table(self) -> int:
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)
Expand Down Expand Up @@ -227,8 +241,8 @@ def append(self, key: Key | str | None, item: Item) -> Container:
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

Expand Down Expand Up @@ -286,7 +300,7 @@ def append(self, key: Key | str | None, item: Item) -> Container:
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):
Expand All @@ -297,7 +311,7 @@ def _raw_append(self, key: Key, item: Item) -> None:
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))
Expand Down Expand Up @@ -605,21 +619,8 @@ def __iter__(self) -> Iterator[str]:

# 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
Expand Down Expand Up @@ -700,12 +701,18 @@ def _replace_at(
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)
Expand Down Expand Up @@ -792,11 +799,13 @@ def __init__(self, container: Container, indices: tuple[int]) -> None:
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()

Expand Down
19 changes: 15 additions & 4 deletions pipenv/vendor/tomlkit/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,12 +667,22 @@ def _getstate(self, protocol=3):
__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):
"""
Expand Down Expand Up @@ -1607,7 +1617,7 @@ def raw_append(self, key: Key | str | None, _item: Any) -> Table:
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
Expand Down Expand Up @@ -1655,6 +1665,7 @@ def indent(self, indent: int) -> Table:
return self

def invalidate_display_name(self):
"""Call ``invalidate_display_name`` on the contained tables"""
self.display_name = None

for child in self.values():
Expand Down Expand Up @@ -1935,7 +1946,7 @@ class Null(Item):
"""

def __init__(self) -> None:
pass
super().__init__(Trivia(trail=""))

def unwrap(self) -> None:
return None
Expand Down
2 changes: 1 addition & 1 deletion pipenv/vendor/tomlkit/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ def _parse_table(
InternalParserError,
"_parse_item() returned None on a non-bracket character.",
)

table.value._validate_out_of_order_table()
if isinstance(result, Null):
result = table

Expand Down
2 changes: 1 addition & 1 deletion pipenv/vendor/vendor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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