Skip to content

Help on KeyError being raised #24

Description

@chrizzFTD

Hi, first of all thanks for this package!

I've found very useful the ability to hash immutable mappings.

Recently I came across a very strange issue and I can not tell why it's happening. I was able to reproduce it with this snippet:

Python 3.8.2 (default, Mar 26 2020, 15:53:00)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from immutables import Map
>>> keys = range(27)
>>> new_entries = dict.fromkeys(keys, True)
>>> m = Map(new_entries)
>>> print(f"{17 in m=}")
17 in m=True
>>>
>>> with m.mutate() as mm:
...     for i in keys:
...         print(f"Deleting {i=}")
...         try:
...             del mm[i]
...         except KeyError as exc:
...             print(f"Did not find: {i}")
...             print(f"{i in m=}")
...             print(f"{i in mm=}")
...             print(type(i))
...             raise
...     mm.update(new_entries)
...     m2 = mm.finish()
...     print("ok")
...
Deleting i=0
Deleting i=1
Deleting i=2
Deleting i=3
Deleting i=4
Deleting i=5
Deleting i=6
Deleting i=7
Deleting i=8
Deleting i=9
Deleting i=10
Deleting i=11
Deleting i=12
Deleting i=13
Deleting i=14
Deleting i=15
Deleting i=16
Deleting i=17
Did not find: 17
i in m=True
i in mm=False
<class 'int'>
Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
KeyError: 17
>>> m.delete(17)
<immutables.Map({0: True, 1: True, 2: True, 3: True, 4: True, 5: True, 6: True, 7: True, 8: True, 9: True, 10: True, 11: True, 12: True, 13: True
, 14: True, 15: True, 16: True, 18: True, 19: True, 20: True, 21: True, 22: True, 23: True, 24: True, 25: True, 26: True}) at 0x7ff586fb57c0>
>>>

Every key after 17 is not able to be deleted on the mutate context manager, but they are in the mapping. I would expect mutate to be able to delete everything.

Is that expectation correct?

Tested on windows:

Python 3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
>>> import immutables
>>> immutables.__version__
'0.11'

ubuntu WSL

Python 3.8.2 (default, Mar 26 2020, 15:53:00)
[GCC 7.3.0] :: Anaconda, Inc. on linux
>>> import immutables
>>> immutables.__version__
'0.11'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions