Skip to content

Commit 62c11f3

Browse files
authored
Merge pull request #6024 from deivid-rodriguez/vendor-latest-tomlkit
Vendor latest tomlkit
2 parents 247a143 + 054df4d commit 62c11f3

File tree

6 files changed

+51
-30
lines changed

6 files changed

+51
-30
lines changed

news/6024.vendor.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update vendored tomlkit to ``0.12.3``

pipenv/vendor/tomlkit/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from pipenv.vendor.tomlkit.api import ws
2828

2929

30-
__version__ = "0.12.1"
30+
__version__ = "0.12.3"
3131
__all__ = [
3232
"aot",
3333
"array",

pipenv/vendor/tomlkit/container.py

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def body(self) -> list[tuple[Key | None, Item]]:
4444
return self._body
4545

4646
def unwrap(self) -> dict[str, Any]:
47+
"""Returns as pure python object (ppo)"""
4748
unwrapped = {}
4849
for k, v in self.items():
4950
if k is None:
@@ -64,6 +65,7 @@ def unwrap(self) -> dict[str, Any]:
6465

6566
@property
6667
def value(self) -> dict[str, Any]:
68+
"""The wrapped dict value"""
6769
d = {}
6870
for k, v in self._body:
6971
if k is None:
@@ -145,7 +147,19 @@ def _get_last_index_before_table(self) -> int:
145147
last_index = i
146148
return last_index + 1
147149

148-
def append(self, key: Key | str | None, item: Item) -> Container:
150+
def _validate_out_of_order_table(self, key: SingleKey | None = None) -> None:
151+
if key is None:
152+
for k in self._map:
153+
assert k is not None
154+
self._validate_out_of_order_table(k)
155+
return
156+
if key not in self._map or not isinstance(self._map[key], tuple):
157+
return
158+
OutOfOrderTableProxy(self, self._map[key])
159+
160+
def append(
161+
self, key: Key | str | None, item: Item, validate: bool = True
162+
) -> Container:
149163
"""Similar to :meth:`add` but both key and value must be given."""
150164
if not isinstance(key, Key) and key is not None:
151165
key = SingleKey(key)
@@ -227,8 +241,8 @@ def append(self, key: Key | str | None, item: Item) -> Container:
227241
else:
228242
self._raw_append(key, item)
229243

230-
# Building a temporary proxy to check for errors
231-
OutOfOrderTableProxy(self, self._map[key])
244+
if validate:
245+
self._validate_out_of_order_table(key)
232246

233247
return self
234248

@@ -286,7 +300,7 @@ def append(self, key: Key | str | None, item: Item) -> Container:
286300
self._raw_append(key, item)
287301
return self
288302

289-
def _raw_append(self, key: Key, item: Item) -> None:
303+
def _raw_append(self, key: Key | None, item: Item) -> None:
290304
if key in self._map:
291305
current_idx = self._map[key]
292306
if not isinstance(current_idx, tuple):
@@ -297,7 +311,7 @@ def _raw_append(self, key: Key, item: Item) -> None:
297311
raise KeyAlreadyPresent(key)
298312

299313
self._map[key] = current_idx + (len(self._body),)
300-
else:
314+
elif key is not None:
301315
self._map[key] = len(self._body)
302316

303317
self._body.append((key, item))
@@ -605,21 +619,8 @@ def __iter__(self) -> Iterator[str]:
605619

606620
# Dictionary methods
607621
def __getitem__(self, key: Key | str) -> Item | Container:
608-
if not isinstance(key, Key):
609-
key = SingleKey(key)
610-
611-
idx = self._map.get(key)
612-
if idx is None:
613-
raise NonExistentKey(key)
614-
615-
if isinstance(idx, tuple):
616-
# The item we are getting is an out of order table
617-
# so we need a proxy to retrieve the proper objects
618-
# from the parent container
619-
return OutOfOrderTableProxy(self, idx)
620-
621-
item = self._body[idx][1]
622-
if item.is_boolean():
622+
item = self.item(key)
623+
if isinstance(item, Item) and item.is_boolean():
623624
return item.value
624625

625626
return item
@@ -700,12 +701,18 @@ def _replace_at(
700701
if isinstance(value, Table):
701702
# Insert a cosmetic new line for tables if:
702703
# - it does not have it yet OR is not followed by one
703-
# - it is not the last item
704+
# - it is not the last item, or
705+
# - The table being replaced has a newline
704706
last, _ = self._previous_item_with_index()
705707
idx = last if idx < 0 else idx
706708
has_ws = ends_with_whitespace(value)
709+
replace_has_ws = (
710+
isinstance(v, Table)
711+
and v.value.body
712+
and isinstance(v.value.body[-1][1], Whitespace)
713+
)
707714
next_ws = idx < last and isinstance(self._body[idx + 1][1], Whitespace)
708-
if idx < last and not (next_ws or has_ws):
715+
if (idx < last or replace_has_ws) and not (next_ws or has_ws):
709716
value.append(None, Whitespace("\n"))
710717

711718
dict.__setitem__(self, new_key.key, value.value)
@@ -792,11 +799,13 @@ def __init__(self, container: Container, indices: tuple[int]) -> None:
792799
self._tables.append(item)
793800
table_idx = len(self._tables) - 1
794801
for k, v in item.value.body:
795-
self._internal_container.append(k, v)
802+
self._internal_container.append(k, v, validate=False)
796803
self._tables_map[k] = table_idx
797804
if k is not None:
798805
dict.__setitem__(self, k.key, v)
799806

807+
self._internal_container._validate_out_of_order_table()
808+
800809
def unwrap(self) -> str:
801810
return self._internal_container.unwrap()
802811

pipenv/vendor/tomlkit/items.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,12 +667,22 @@ def _getstate(self, protocol=3):
667667
__rpow__ = wrap_method(int.__rpow__)
668668
__rrshift__ = wrap_method(int.__rrshift__)
669669
__rshift__ = wrap_method(int.__rshift__)
670-
__rtruediv__ = wrap_method(int.__rtruediv__)
671670
__rxor__ = wrap_method(int.__rxor__)
672-
__truediv__ = wrap_method(int.__truediv__)
673671
__trunc__ = wrap_method(int.__trunc__)
674672
__xor__ = wrap_method(int.__xor__)
675673

674+
def __rtruediv__(self, other):
675+
result = int.__rtruediv__(self, other)
676+
if result is NotImplemented:
677+
return result
678+
return Float._new(self, result)
679+
680+
def __truediv__(self, other):
681+
result = int.__truediv__(self, other)
682+
if result is NotImplemented:
683+
return result
684+
return Float._new(self, result)
685+
676686

677687
class Float(Item, _CustomFloat):
678688
"""
@@ -1607,7 +1617,7 @@ def raw_append(self, key: Key | str | None, _item: Any) -> Table:
16071617
if not isinstance(_item, Item):
16081618
_item = item(_item)
16091619

1610-
self._value.append(key, _item)
1620+
self._value.append(key, _item, validate=False)
16111621

16121622
if isinstance(key, Key):
16131623
key = next(iter(key)).key
@@ -1655,6 +1665,7 @@ def indent(self, indent: int) -> Table:
16551665
return self
16561666

16571667
def invalidate_display_name(self):
1668+
"""Call ``invalidate_display_name`` on the contained tables"""
16581669
self.display_name = None
16591670

16601671
for child in self.values():
@@ -1935,7 +1946,7 @@ class Null(Item):
19351946
"""
19361947

19371948
def __init__(self) -> None:
1938-
pass
1949+
super().__init__(Trivia(trail=""))
19391950

19401951
def unwrap(self) -> None:
19411952
return None

pipenv/vendor/tomlkit/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ def _parse_table(
10301030
InternalParserError,
10311031
"_parse_item() returned None on a non-bracket character.",
10321032
)
1033-
1033+
table.value._validate_out_of_order_table()
10341034
if isinstance(result, Null):
10351035
result = table
10361036

pipenv/vendor/vendor.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ pythonfinder==2.0.6
1313
ruamel.yaml==0.17.39
1414
shellingham==1.5.3
1515
tomli==2.0.1
16-
tomlkit==0.12.1
16+
tomlkit==0.12.3

0 commit comments

Comments
 (0)