Skip to content

Commit

Permalink
Allow heterogenous arrays (#92)
Browse files Browse the repository at this point in the history
The 1.0.0 version of the TOML specification allows heterogenous arrays
  • Loading branch information
sdispater authored Apr 12, 2020
1 parent cac5893 commit 3bff550
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 21 deletions.
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ def _example(name):


TEST_DIR = os.path.join(os.path.dirname(__file__), "toml-test", "tests")
IGNORED_TESTS = {
"invalid": [
"array-mixed-types-strings-and-ints.toml",
"array-mixed-types-arrays-and-ints.toml",
"array-mixed-types-ints-and-floats.toml",
]
}


def get_tomltest_cases():
Expand All @@ -52,8 +59,12 @@ def get_tomltest_cases():
rv = {}
for d in dirs:
rv[d] = {}
ignored = IGNORED_TESTS.get(d, [])
files = os.listdir(os.path.join(TEST_DIR, d))
for f in files:
if f in ignored:
continue

bn, ext = f.rsplit(".", 1)
if bn not in rv[d]:
rv[d][bn] = {}
Expand Down
1 change: 0 additions & 1 deletion tests/examples/invalid/mixed_array_types.toml

This file was deleted.

1 change: 0 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def test_parsed_document_are_properly_json_representable(
("section_with_trailing_characters", UnexpectedCharError),
("key_value_with_trailing_chars", UnexpectedCharError),
("array_with_invalid_chars", UnexpectedCharError),
("mixed_array_types", MixedArrayTypesError),
("invalid_number", InvalidNumberError),
("invalid_date", InvalidDateError),
("invalid_time", InvalidTimeError),
Expand Down
15 changes: 0 additions & 15 deletions tomlkit/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,18 +762,6 @@ def discriminant(self): # type: () -> int
def value(self): # type: () -> list
return self

def is_homogeneous(self): # type: () -> bool
if not self:
return True

discriminants = [
i.discriminant
for i in self._value
if not isinstance(i, (Whitespace, Comment))
]

return len(set(discriminants)) == 1

def multiline(self, multiline): # type: (bool) -> self
self._multiline = multiline

Expand Down Expand Up @@ -801,9 +789,6 @@ def append(self, _item): # type: () -> None

self._value.append(it)

if not self.is_homogeneous():
raise ValueError("Array has mixed types elements")

if not PY2:

def clear(self):
Expand Down
5 changes: 1 addition & 4 deletions tomlkit/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,7 @@ def _parse_array(self): # type: () -> Array
except ValueError:
pass
else:
if res.is_homogeneous():
return res

raise self.parse_error(MixedArrayTypesError)
return res

def _parse_inline_table(self): # type: () -> InlineTable
# consume opening bracket, EOF here is an issue (middle of array)
Expand Down

0 comments on commit 3bff550

Please sign in to comment.