Fix a round of issues#2
Open
will-keen wants to merge 10 commits into
Open
Conversation
debug_info was assigned the typing construct Optional[RandomizationDebugInfo] instead of a value, so failure paths could stringify the typing object rather than real debug info. Initialise it to None.
The check only looked at 'length', so a list whose length is itself random was accepted as a rand_length variable, despite a list-valued length being illegal. Use is_list(), which covers both fixed and random lengths.
Both error messages interpolated the variable being added rather than the offending rand_length argument, making them misleading.
Range domains were randomized with randrange(start, stop), ignoring the step. Values outside the domain were returned, and ranges with a negative step raised ValueError.
Constraining a random-length list did not mark the variable defining its length as constrained. The length then kept its first random value through all solver stages, so solvable problems failed. Propagate in add_constraint and for temporary constraints.
When with_values gave a value for every variable in a MultiVarProblem, determine_order indexed an empty list and raised IndexError. Use one empty group so the values are still checked against the constraints.
When a constrained length variable was re-randomized, its dependent list variables were re-randomized too, even when given a concrete value in with_values, discarding the given value.
is_pure raised TypeError for callables such as functools.partial, because getclosurevars only accepts plain functions. This made add_rand_var and add_constraint crash for such constraints. Treat them as impure instead.
add_constraint appended the constraint before checking the variable names, so a failed call left the constraint registered and every later randomize raised KeyError.
weighted_choice returned the single-element list from random.choices, contradicting its docstring. Return the value itself. dist no longer needs to index the result.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Each one contains a description and a unit test