Skip to content

potential pypy mutability bug #620

Closed
@iscai-msft

Description

@iscai-msft

Describe the bug

when using pypy and mutating a CIMultiDict, I get a RuntimeError of "Dictionary changed during iteration". This doesn't happen using regular python, and I don't see this error when using pypy and other kinds of dictionaries.

To Reproduce

I've added the following tests to repro with pypy

@pytest.mark.asyncio
async def test_headers_response_items_multidict_compare():
    h = CIMultiDict({'a': '123, 456', 'b': '789'})
    before_mutation_items = h.items()
    h['c'] = '000'
    with pytest.raises(RuntimeError):
        list(before_mutation_items)

def test_headers_response_items_requests_compare():
    from requests.structures import CaseInsensitiveDict
    h = CaseInsensitiveDict({'a': '123, 456', 'b': '789'})
    before_mutation_items = h.items()
    h['c'] = '000'
    list(before_mutation_items)

def test_headers_response_items_python_compare():
    h = {'a': '123, 456', 'b': '789'}
    before_mutation_items = h.items()
    h['c'] = '000'
    list(before_mutation_items)

Expected behavior

My thinking is that if mutating the dictionary doesn't raise for regular python is that it shouldn't raise for pypy. Is this expected behavior?

Logs/tracebacks

self = _ItemsView('a': '123, 456', 'b': '789', 'c': '000')

    def _iter(self):
        for i, k, v in self._impl._items:
            if self._version != self._impl._version:
>               raise RuntimeError("Dictionary changed during iteration")
E               RuntimeError: Dictionary changed during iteration

envs/corepypy3venv/site-packages/multidict/_multidict_py.py:459: RuntimeError

Python Version

$ python --version
Python 3.7.10 (51efa818fd9b24f625078c65e8e2f6a5ac24d572, Apr 08 2021, 17:43:00)
[PyPy 7.3.4 with GCC Apple LLVM 12.0.0 (clang-1200.0.32.29)]

aiohttp Version

$ python -m pip show aiohttp
Version: 3.7.4.post0

multidict Version

$ python -m pip show multidict
Version: 5.1.0

yarl Version

$ python -m pip show yarl
Version: 1.6.3

OS

macOS

Related component

Client

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions