swaroopch / edn_format

EDN reader and writer implementation in Python, using PLY (lex, yacc)
https://swaroopch.com/2012/12/24/edn-format-python/
Other
131 stars 30 forks source link

ImmutableDicts should throw errors on attempted mutation #88

Open presheaf opened 1 month ago

presheaf commented 1 month ago

When you attempt to e.g. insert a key in an ImmutableDict object, nothing happens - no error is thrown or anything. This means that bugs can pass undetected, and is unfortunate. For example, I was parsing an EDN file and forgot that the map within it would become immutable, treating it as a regular Python dict by attempting to insert keys, then ran into strange behavior because my insertions were being silently ignored. See below for an example:

import edn_format
d = edn_format.immutable_dict.ImmutableDict({"apple": 1, "pear": 2})
d["banana"] = 3                 # does not throw an error, just is silently ignored
print(d["banana"])              # oops, KeyError
swaroopch commented 1 month ago

Hi! Thanks for reporting the issue. I have not used or updated this library in a while, so I'm unlikely to look into this myself. I would encourage & welcome pull requests to fix this issue. Thanks.