Skip to content

Commit

Permalink
Fix MultiDict.items().isdisjoint() for C Extensions
Browse files Browse the repository at this point in the history
These changes fix a mismatch at `views.h` that causes `SystemError: null argument to internal routine` when calling `MultiDict.items().isdisjoint()`.

PR #927
  • Loading branch information
Jamim committed Jan 20, 2024
1 parent 68b080e commit 82b559c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES/927.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed a ``SystemError: null argument to internal routine`` error on
a ``MultiDict.items().isdisjoint()`` call when using C Extensions.
2 changes: 1 addition & 1 deletion multidict/_multilib/views.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ multidict_views_init(void)
GET_MOD_ATTR(abc_keysview_register_func, "_abc_keysview_register");
GET_MOD_ATTR(abc_valuesview_register_func, "_abc_valuesview_register");

GET_MOD_ATTR(itemsview_repr_func, "_itemsview_isdisjoint");
GET_MOD_ATTR(itemsview_isdisjoint_func, "_itemsview_isdisjoint");
GET_MOD_ATTR(itemsview_repr_func, "_itemsview_repr");

GET_MOD_ATTR(keysview_repr_func, "_keysview_repr");
Expand Down
11 changes: 7 additions & 4 deletions tests/test_multidict.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,16 @@ def test_xor2(self, cls: Type[MutableMultiMapping[str]]) -> None:

assert {"key", "key3"} == {"key2", "key3"} ^ d.keys()

@pytest.mark.parametrize(("set_", "expected"), (({"key2"}, True), ({"key"}, False)))
@pytest.mark.parametrize(
("key", "value", "expected"),
(("key2", "v", True), ("key", "value1", False)),
)
def test_isdisjoint(
self, cls: Type[MutableMultiMapping[str]], set_: Set[str], expected: bool
self, cls: Type[MutableMultiMapping[str]], key: str, value: str, expected: bool
) -> None:
d = cls([("key", "value1")])

assert d.keys().isdisjoint(set_) == expected
assert d.items().isdisjoint({(key, value)}) is expected
assert d.keys().isdisjoint({key}) is expected

def test_repr_aiohttp_issue_410(self, cls: Type[MutableMultiMapping[str]]) -> None:
d = cls()
Expand Down

0 comments on commit 82b559c

Please sign in to comment.