Generate random Python from a corpus of examples
- The function
give_me_random_code
generates a new code example from a corpus - The class
RandomCodeSource
will continually generate new code samples from a corpus
The code was inspired by Wave Function Collapse by Maxim Gumin to exchange subsets of examples from the corpus in a random fashion to arrive at new code blocks
Things that Work:
- Running the default script on a small custom example
- Running the example script on an a big codebase
- Check variable names are in scope
- Tests that verify important functions
Things that are planned to work in the future:
- Exchange elements with elements of the exact same type, so the logic is likely useful
- Exchange similar elements (e.g. import/import from, replacing an integer with a function that returns an integer)
Generated with script big_example.py
from hypothesis https://github.com/HypothesisWorks/hypothesis/commit/b6633778e8687e64e039b050b792adab1135a17e
from hypothesis.utils.conventions import settings
def check_invariants(self, argname: str):
assert (- 1.5)
def __repr__(self):
return 'hi'