From 57763b39ae202f5917fab1e8cfdd1cb78c9788f4 Mon Sep 17 00:00:00 2001 From: laixintao Date: Wed, 10 Aug 2022 08:12:35 +0800 Subject: [PATCH] fix: items.Array __init__ didn't ignore Null that _group_values (#221) added. --- tests/test_items.py | 15 +++++++++++++++ tomlkit/items.py | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/test_items.py b/tests/test_items.py index edf77a1..7f875ce 100644 --- a/tests/test_items.py +++ b/tests/test_items.py @@ -1,5 +1,6 @@ import math import pickle +import copy from datetime import date from datetime import datetime @@ -860,3 +861,17 @@ def test_table_copy(): table["foo"] = "baz" assert table_copy["foo"] == "bar" assert table_copy.as_string() == 'foo = "bar"\n' + + +def test_copy_copy(): + result = parse(""" + [tool.poetry] + classifiers = [ + # comment + "a", + "b", + ] + """) + classifiers = result["tool"]["poetry"]["classifiers"] + new = copy.copy(classifiers) + assert new == classifiers diff --git a/tomlkit/items.py b/tomlkit/items.py index 5128807..f4ca6d9 100644 --- a/tomlkit/items.py +++ b/tomlkit/items.py @@ -656,7 +656,6 @@ def as_string(self) -> str: return self._raw def __add__(self, other): - return self._new(int(self._raw) + other) def __radd__(self, other): @@ -1139,7 +1138,8 @@ def __init__( ) -> None: super().__init__(trivia) list.__init__( - self, [v.value for v in value if not isinstance(v, (Whitespace, Comment))] + self, + [v.value for v in value if not isinstance(v, (Whitespace, Comment, Null))], ) self._index_map: Dict[int, int] = {} self._value = self._group_values(value)