Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically copy the cached dict result from generate_packet_map
Before this change, if the user called `generate_packet_map`, a dict object would get cached, and that same object (reference) would be actually returned. This means that when the fucntion would get called again, the same cached dict would be returned. Generally, this wouldn't be an issue, however if the user modifies this returned dictionary, since caching only stores the very same reference, on next call the modified version of that dict would be returned again. This was mentioned in the function's docstring as a warning, however I don't see that as sufficient, as people will usually do stupid things with libraries, without reading the docs, which in this case, would potentially end up breaking a lot of things. To avoid this issue, another decorrator was created, responsible for copying the returned object after the cache decorator. That means the cached version will hold a dict that no user will be able to modify accidentally, as the returned dict will simply be a copy of it. This does mean using slightly more memory, but it's a pretty small amount, and it's well worth the potential mess-ups this prevents.
- Loading branch information