Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help on KeyError being raised #24

Closed
chrizzFTD opened this issue Apr 3, 2020 · 1 comment
Closed

Help on KeyError being raised #24

chrizzFTD opened this issue Apr 3, 2020 · 1 comment

Comments

@chrizzFTD
Copy link

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'
1st1 added a commit that referenced this issue Apr 23, 2020
* Fix #26: `ifdef NDEBUG` should be `ifndef NDEBUG`
* More tests for #24
* Add a `DEBUG_IMMUTABLES` env var to build debug builds
@chrizzFTD
Copy link
Author

Some releases have been done on linked PRs and this is no longer an issue as of version 0.14

Thanks @TIGirardi and @1st1 !

P.S. big fan <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant