Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow heterogeneous arrays #92

Merged
merged 1 commit into from
Apr 12, 2020
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
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