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

Register contracts for nondeterministic functions in the standard library #162

Open
4 of 7 tasks
pschanely opened this issue May 17, 2022 · 2 comments
Open
4 of 7 tasks

Comments

@pschanely
Copy link
Owner

pschanely commented May 17, 2022

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:

  • time.time
  • time.uniform
  • random.choice
  • random.randint / randrange / uniform / random / randbits
  • functools.lru_cache / cache
  • sys.stdin
  • uuid.uuid*
@pschanely
Copy link
Owner Author

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.

@pschanely
Copy link
Owner Author

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 2ab5105

Now, you won't get non-deterministic errors when analyzing behavior that involves these caches!

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

No branches or pull requests

1 participant