CrossHair
CrossHair copied to clipboard
Register contracts for nondeterministic functions in the standard library
We now have some effective strategies for dealing with non-deterministic behavior, by adding contracts to existing functions. Let's apply them to the standard library. Some high-priority ones off the top of my head:
- [x] time.time
- [x] time.uniform
- [ ] random.choice
- [x] random.randint / randrange / uniform / random / randbits
- [x] functools.lru_cache / cache
- [ ] sys.stdin
- [ ] uuid.uuid*
The remaining ones may require even more capabilities. I'm not immediately prioritizing them.
For instance, I'd like to simply disable lru_cache and friends, but it seems like we'd need to intercept it at import time rather than at run time. For stdin, I'd like to intercept only the read() bound to stdin, not to any TextIOWrapper.
I figured out a workaround for disabling the caching behaviors of lru_cache and cache: we dynamically detect the wrapper functions at runtime and skip the caching bits. Implemented in 2ab5105aba83e8b26a40e9a1362a946fc8b13644
Now, you won't get non-deterministic errors when analyzing behavior that involves these caches!