Skip to content

Commit

Permalink
bias less towards classes over functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Meyer committed May 18, 2023
1 parent fec3184 commit 1f98dce
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ them on a Python build.

To use, create a Python 3.11 venv and `pip install -r frozen.txt`.

Then start the evalserver with your built Python:
Then start the evalserver with the build of Python you want to test for
compatibility with 3.11:

/home/carljm/cpython-builds/dbg/python evalserver.py

Expand All @@ -18,8 +19,8 @@ the log file.

Current approach is to generate a bunch of random code samples and filter down
to the ones containing list comprehensions, then aim for samples that maximize
number of listcomps and lambdas. The problem is that too many samples are
generated without listcomps and then rejected. We probably need a more
number of listcomps, lambdas, and classes. The problem is that too many samples
are generated without listcomps and then rejected. We probably need a more
constrained format for generating the samples initially, but without
over-constraining and possibly missing counter-examples.

Expand Down
13 changes: 11 additions & 2 deletions test_fuzz_comps.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,22 @@ def record_targets(tree: ast.Module) -> ast.Module:
num_lambdas = 0
num_listcomps = 0
num_classes = 0
num_functions = 0
for n in nodes:
if isinstance(n, ast.Lambda):
num_lambdas += 1
elif isinstance(n, ast.ListComp):
num_listcomps += 1
elif isinstance(n, ast.ClassDef):
num_classes += 100
num_classes += 1

This comment has been minimized.

Copy link
@JelleZijlstra

JelleZijlstra May 18, 2023

Collaborator

FYI my experience was that this didn't make much difference; when i ran it with both top-level functions and classes, but with this 100-fold boost, I still got a lot of functions. The hypothesis docs suggest that the boost takes a long time (on the order of 10k attempts) to take effect, so maybe that's why.

This comment has been minimized.

Copy link
@carljm

carljm May 18, 2023

Owner

Yeah I wasn't sure how much difference this made. The main point of this commit was to allow top-level functions, although that's kind of a regression in usefulness until we also have (2) to evaluate their namespaces.

elif isinstance(n, ast.FunctionDef):
num_functions += 1
# hypothesis will aim for samples that maximize these metrics
for value, label in [
(num_lambdas, "(modules) number of lambdas"),
(num_listcomps, "(modules) number of listcomps"),
(num_classes, "(modules) number of classes"),
(num_functions, "(modules) number of functions"),
]:
target(float(value), label=label)
return to_source(tree)
Expand Down Expand Up @@ -259,7 +263,12 @@ def functions(draw):


def module_level_statements():
return st.from_type(ast.ClassDef)
# require top-level class or function; plain module-level comprehensions are
# not very interesting in terms of finding scoping bugs
return st.one_of(
st.from_type(ast.ClassDef),
st.from_type(ast.FunctionDef)
)


st.register_type_strategy(
Expand Down

0 comments on commit 1f98dce

Please sign in to comment.