nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: reduxjs/redux-toolkit
Pull request #1029 (2021-04-30 14:16:00)

fix/default serialize query args
fixes https://github.com/rtk-incubator/rtk-query/issues/225


Patch:
diff --git a/src/query/defaultSerializeQueryArgs.ts b/src/query/defaultSerializeQueryArgs.ts
index 10ea6d74..505903ce 100644
--- a/src/query/defaultSerializeQueryArgs.ts
+++ b/src/query/defaultSerializeQueryArgs.ts
@@ -1,14 +1,21 @@
 import { QueryCacheKey } from './core/apiState'
 import { EndpointDefinition } from './endpointDefinitions'
+import { isPlainObject } from '@reduxjs/toolkit'
 
 export const defaultSerializeQueryArgs: SerializeQueryArgs<any> = ({
   endpointName,
   queryArgs,
 }) => {
   // Sort the object keys before stringifying, to prevent useQuery({ a: 1, b: 2 }) having a different cache key than useQuery({ b: 2, a: 1 })
-  return `${endpointName}(${JSON.stringify(
-    queryArgs,
-    Object.keys(queryArgs || {}).sort()
+  return `${endpointName}(${JSON.stringify(queryArgs, (key, value) =>
+    isPlainObject(value)
+      ? Object.keys(value)
+          .sort()
+          .reduce<any>((acc, key) => {
+            acc[key] = (value as any)[key]
+            return acc
+          }, {})
+      : value
   )})`
 }
 


Test patch:
diff --git a/src/query/tests/defaultSerializeQueryArgs.test.ts b/src/query/tests/defaultSerializeQueryArgs.test.ts
new file mode 100644
index 00000000..02040228
--- /dev/null
+++ b/src/query/tests/defaultSerializeQueryArgs.test.ts
@@ -0,0 +1,46 @@
+import { defaultSerializeQueryArgs } from '@internal/query/defaultSerializeQueryArgs'
+
+const endpointDefinition: any = {}
+const endpointName = 'test'
+
+test('string arg', () => {
+  expect(
+    defaultSerializeQueryArgs({
+      endpointDefinition,
+      endpointName,
+      queryArgs: 'arg',
+    })
+  ).toMatchInlineSnapshot(`"test(\\"arg\\")"`)
+})
+
+test('number arg', () => {
+  expect(
+    defaultSerializeQueryArgs({
+      endpointDefinition,
+      endpointName,
+      queryArgs: 5,
+    })
+  ).toMatchInlineSnapshot(`"test(5)"`)
+})
+
+test('simple object arg is sorted', () => {
+  expect(
+    defaultSerializeQueryArgs({
+      endpointDefinition,
+      endpointName,
+      queryArgs: { name: 'arg', age: 5 },
+    })
+  ).toMatchInlineSnapshot(`"test({\\"age\\":5,\\"name\\":\\"arg\\"})"`)
+})
+
+test('nested object arg is sorted recursively', () => {
+  expect(
+    defaultSerializeQueryArgs({
+      endpointDefinition,
+      endpointName,
+      queryArgs: { name: { last: 'Split', first: 'Banana' }, age: 5 },
+    })
+  ).toMatchInlineSnapshot(
+    `"test({\\"age\\":5,\\"name\\":{\\"first\\":\\"Banana\\",\\"last\\":\\"Split\\"}})"`
+  )
+})
Repository: sdispater/tomlkit
Pull request #139 (2021-07-25 16:17:10)

Fix bug in string output of empty array
```python
>>> from tomlkit import item, dumps, loads
>>> t = item([])
>>> t.multiline(True)
[]
>>> print(dumps(t))
[
    ,
]
>>> loads(dumps(t))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/thirdegree/.virtualenvs/tmp-b9dbc870a56cb56/lib/python3.6/site-packages/tomlkit/api.py", line 34, in loads
    return parse(string)
  File "/home/thirdegree/.virtualenvs/tmp-b9dbc870a56cb56/lib/python3.6/site-packages/tomlkit/api.py", line 51, in parse
    return Parser(string).parse()
  File "/home/thirdegree/.virtualenvs/tmp-b9dbc870a56cb56/lib/python3.6/site-packages/tomlkit/parser.py", line 160, in parse
    key, value = self._parse_table()
  File "/home/thirdegree/.virtualenvs/tmp-b9dbc870a56cb56/lib/python3.6/site-packages/tomlkit/parser.py", line 1076, in _parse_table
    name_parts = tuple(self._split_table_name(name))
  File "/home/thirdegree/.virtualenvs/tmp-b9dbc870a56cb56/lib/python3.6/site-packages/tomlkit/parser.py", line 267, in _split_table_name
    raise self.parse_error()
tomlkit.exceptions.ParseError: TOML parse error at line 3 col 0
>>>
```


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 99dc90f..3fd1de5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@
 
 ### Fixed
 
+- Fix the invalid dumping output of multiline array when it is empty. ([#139](https://github.com/sdispater/tomlkit/issues/#139))
 - Fix a bug that tomlkit accepts an invalid table with missing `=`. ([#141](https://github.com/sdispater/tomlkit/issues/141))
 - Fix the invalid dumping output when the key is empty. ([#143](https://github.com/sdispater/tomlkit/issues/143))
 - Fix incorrect string returned by dumps when moving/renaming table. ([#144](https://github.com/sdispater/tomlkit/issues/144))
diff --git a/tomlkit/items.py b/tomlkit/items.py
index 863d9f3..4beccf0 100644
--- a/tomlkit/items.py
+++ b/tomlkit/items.py
@@ -850,7 +850,7 @@ class Array(Item, _CustomList):
         return self
 
     def as_string(self) -> str:
-        if not self._multiline:
+        if not self._multiline or not self._value:
             return "[{}]".format("".join(v.as_string() for v in self._value))
 
         s = "[\n" + self.trivia.indent + " " * 4


Test patch:
diff --git a/tests/test_items.py b/tests/test_items.py
index 40c299a..3cfaa34 100644
--- a/tests/test_items.py
+++ b/tests/test_items.py
@@ -199,6 +199,7 @@ def test_array_multiline():
     assert expected == t.as_string()
 
     t = item([])
+    t.multiline(True)
 
     assert "[]" == t.as_string()
Repository: sdispater/tomlkit
Pull request #175 (2022-02-08 10:46:24)

Make supertables if the only child id a table-like item


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ae74e33..e5808b6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,10 @@
 # Change Log
 
-## [Unreleased]
+## [0.9.2] - 2022-02-08
+
+### Changed
+
+- When a table's only child is a table or array of table, it is created as a super table. ([#175](https://github.com/sdispater/tomlkit/issues/175))
 
 ## [0.9.1] - 2022-02-07
 
@@ -241,7 +245,8 @@
 - Fixed handling of super tables with different sections.
 - Fixed raw strings escaping.
 
-[unreleased]: https://github.com/sdispater/tomlkit/compare/0.9.1...master
+[unreleased]: https://github.com/sdispater/tomlkit/compare/0.9.2...master
+[0.9.2]: https://github.com/sdispater/tomlkit/releases/tag/0.9.2
 [0.9.1]: https://github.com/sdispater/tomlkit/releases/tag/0.9.1
 [0.9.0]: https://github.com/sdispater/tomlkit/releases/tag/0.9.0
 [0.8.0]: https://github.com/sdispater/tomlkit/releases/tag/0.8.0
diff --git a/pyproject.toml b/pyproject.toml
index a38f9b8..a937af7 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
 [tool.poetry]
 name = "tomlkit"
-version = "0.9.1"
+version = "0.9.2"
 description = "Style preserving TOML library"
 authors = ["Sébastien Eustace <sebastien@eustace.io>"]
 license = "MIT"
diff --git a/tomlkit/__init__.py b/tomlkit/__init__.py
index 2d15e33..84566d4 100644
--- a/tomlkit/__init__.py
+++ b/tomlkit/__init__.py
@@ -25,7 +25,7 @@ from .api import value
 from .api import ws
 
 
-__version__ = "0.9.1"
+__version__ = "0.9.2"
 __all__ = [
     "aot",
     "array",
diff --git a/tomlkit/items.py b/tomlkit/items.py
index c655784..abbb05f 100644
--- a/tomlkit/items.py
+++ b/tomlkit/items.py
@@ -90,6 +90,14 @@ def item(
             key=lambda i: (isinstance(i[1], dict), i[0] if _sort_keys else 1),
         ):
             val[k] = item(v, _parent=val, _sort_keys=_sort_keys)
+        only_child = len(value) == 1 and val[next(iter(value))]
+        if (
+            table_constructor is Table
+            and only_child
+            and isinstance(only_child, (AoT, Table))
+        ):
+            # The table becomes super table if the only child is a table or AoT.
+            val._is_super_table = True
 
         return val
     elif isinstance(value, (list, tuple)):


Test patch:
diff --git a/tests/test_api.py b/tests/test_api.py
index f4ecf35..88b9772 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -382,3 +382,13 @@ def test_value_rejects_values_with_appendage(raw):
     """Values that appear valid at the beginning but leave chars unparsed are rejected."""
     with pytest.raises(tomlkit.exceptions.ParseError):
         tomlkit.value(raw)
+
+
+def test_create_super_table_with_table():
+    data = {"foo": {"bar": {"a": 1}}}
+    assert dumps(data) == "[foo.bar]\na = 1\n"
+
+
+def test_create_super_table_with_aot():
+    data = {"foo": {"bar": [{"a": 1}]}}
+    assert dumps(data) == "[[foo.bar]]\na = 1\n"
Repository: sdispater/tomlkit
Pull request #221 (2022-08-09 17:01:33)

bugfix: items.Array __init__ didn't ignore Null that _group_values added.
The issue is, #218 added a `_group_values` cloud add `Null` into the Array values, but the `Array`'s `list.__init__` didn't ignore this value.

Poetry will `copy.copy` an `Array` item (for e.g. here: https://github.com/python-poetry/poetry-core/blob/main/src/poetry/core/packages/package.py#L290 ), then there will be an extra `Null` object in the values, so that an Array like this:

```
[tool.poetry]
classifiers = [
# comment
    "a",
    "b",
]
```
originally is `["a", "b"]`, after being `copy.copy`ed, will become `[None, "a", "b"]` due to the `Null`. (Please see the testcase I added)

Then it will cause poetry to fail because there is an extra "None" in classifiers. ( https://github.com/laixintao/iredis/runs/7749027851?check_suite_focus=true )

related: https://github.com/sdispater/tomlkit/pull/218

laixintao: I found this issue in iredis' build:

It coincidentally has a comment line in classifiers:
https://github.com/laixintao/iredis/blob/d0cafb62607868fa9859214d1cefe9ae29d6b273/pyproject.toml#L12

the poetry failure: https://github.com/laixintao/iredis/runs/7749027851?check_suite_focus=true

cc @frostming 

Patch:
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 @@ class Integer(int, Item):
         return self._raw
 
     def __add__(self, other):
-
         return self._new(int(self._raw) + other)
 
     def __radd__(self, other):
@@ -1139,7 +1138,8 @@ class Array(Item, _CustomList):
     ) -> 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)


Test patch:
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
Repository: sdispater/tomlkit
Pull request #312 (2023-09-20 06:55:30)

Fix division for integers
This is a possible fix for https://github.com/sdispater/tomlkit/issues/309. Changes introduced in https://github.com/sdispater/tomlkit/pull/307 made it so that the float result of division on an Integer is wrapped as an Integer, which is incorrect.

I have included a test case which demonstrates the issue.


Patch:
diff --git a/tomlkit/items.py b/tomlkit/items.py
index 75e8ae2..f6346ac 100644
--- a/tomlkit/items.py
+++ b/tomlkit/items.py
@@ -667,12 +667,22 @@ class Integer(Item, _CustomInt):
     __rpow__ = wrap_method(int.__rpow__)
     __rrshift__ = wrap_method(int.__rrshift__)
     __rshift__ = wrap_method(int.__rshift__)
-    __rtruediv__ = wrap_method(int.__rtruediv__)
     __rxor__ = wrap_method(int.__rxor__)
-    __truediv__ = wrap_method(int.__truediv__)
     __trunc__ = wrap_method(int.__trunc__)
     __xor__ = wrap_method(int.__xor__)
 
+    def __rtruediv__(self, other):
+        result = int.__rtruediv__(self, other)
+        if result is NotImplemented:
+            return result
+        return Float._new(self, result)
+
+    def __truediv__(self, other):
+        result = int.__truediv__(self, other)
+        if result is NotImplemented:
+            return result
+        return Float._new(self, result)
+
 
 class Float(Item, _CustomFloat):
     """


Test patch:
diff --git a/tests/test_items.py b/tests/test_items.py
index 783cab3..ca75966 100644
--- a/tests/test_items.py
+++ b/tests/test_items.py
@@ -624,6 +624,10 @@ def test_integers_behave_like_ints():
     assert i == 33
     assert i.as_string() == "33"
 
+    i /= 2
+    assert i == 16.5
+    assert i.as_string() == "16.5"
+
     doc = parse("int = +34")
     doc["int"] += 1