Skip to content

Commit

Permalink
Remove the is_tomlkit check
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming committed May 24, 2022
1 parent deac74d commit a46ac20
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 34 deletions.
8 changes: 0 additions & 8 deletions tests/test_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,10 @@

from tomlkit import api
from tomlkit import parse
from tomlkit.check import is_tomlkit
from tomlkit.exceptions import NonExistentKey
from tomlkit.items import AoT
from tomlkit.items import Array
from tomlkit.items import Bool
from tomlkit.items import Comment
from tomlkit.items import Date
from tomlkit.items import DateTime
from tomlkit.items import Float
from tomlkit.items import InlineTable
from tomlkit.items import Integer
from tomlkit.items import Item
Expand All @@ -28,7 +23,6 @@
from tomlkit.items import String
from tomlkit.items import StringType
from tomlkit.items import Table
from tomlkit.items import Time
from tomlkit.items import Trivia
from tomlkit.items import item
from tomlkit.parser import Parser
Expand Down Expand Up @@ -124,7 +118,6 @@ def test_null_unwrap():

def test_aot_unwrap():
d = item([{"a": "A"}, {"b": "B"}])
assert is_tomlkit(d)
unwrapped = d.unwrap()
assert_is_ppo(unwrapped, list)
for du, dw in zip(unwrapped, d):
Expand Down Expand Up @@ -161,7 +154,6 @@ def test_array_unwrap():
def test_abstract_table_unwrap():
table = item({"foo": "bar"})
super_table = item({"table": table, "baz": "borg"})
assert is_tomlkit(super_table["table"])

table_unwrapped = super_table.unwrap()
sub_table = table_unwrapped["table"]
Expand Down
12 changes: 0 additions & 12 deletions tomlkit/check.py

This file was deleted.

3 changes: 1 addition & 2 deletions tomlkit/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from ._compat import decode
from ._utils import merge_dicts
from .check import is_tomlkit
from .exceptions import KeyAlreadyPresent
from .exceptions import NonExistentKey
from .exceptions import TOMLKitError
Expand Down Expand Up @@ -53,7 +52,7 @@ def unwrap(self) -> str:
if k is None:
continue

if not isinstance(k, str):
if isinstance(k, Key):
k = k.key

if isinstance(v, Item):
Expand Down
19 changes: 7 additions & 12 deletions tomlkit/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from ._compat import decode
from ._utils import CONTROL_CHARS
from ._utils import escape_string
from .check import is_tomlkit
from .exceptions import InvalidStringError
from .toml_char import TOMLChar

Expand Down Expand Up @@ -1091,7 +1090,7 @@ def __init__(self, value: list, trivia: Trivia, multiline: bool = False) -> None
def unwrap(self) -> str:
unwrapped = []
for v in self:
if is_tomlkit(v):
if isinstance(v, Item):
unwrapped.append(v.unwrap())
else:
unwrapped.append(v)
Expand Down Expand Up @@ -1343,16 +1342,12 @@ def __init__(self, value: "container.Container", trivia: Trivia):

def unwrap(self):
unwrapped = {}
for k in self:
if is_tomlkit(k):
nk = k.unwrap()
else:
nk = k
if is_tomlkit(self[k]):
nv = self[k].unwrap()
else:
nv = self[k]
unwrapped[nk] = nv
for k, v in self.items():
if isinstance(k, Key):
k = k.key
if isinstance(v, Item):
v = v.unwrap()
unwrapped[k] = v

return unwrapped

Expand Down

0 comments on commit a46ac20

Please sign in to comment.