From 2f692082d79b7937e6d4e69b5fc491209a56a649 Mon Sep 17 00:00:00 2001 From: Liam DeVoe Date: Sun, 22 Dec 2024 00:44:34 -0500 Subject: [PATCH] linting, more explicit coverage, add release notes --- hypothesis-python/RELEASE.rst | 3 +++ .../src/hypothesis/internal/conjecture/choice.py | 6 ++---- hypothesis-python/tests/conjecture/test_ir.py | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 hypothesis-python/RELEASE.rst diff --git a/hypothesis-python/RELEASE.rst b/hypothesis-python/RELEASE.rst new file mode 100644 index 0000000000..634228bd8c --- /dev/null +++ b/hypothesis-python/RELEASE.rst @@ -0,0 +1,3 @@ +RELEASE_TYPE: patch + +This patch lays some groundwork for migrating our internal representation to the typed choice sequence (:issue:`3921`) diff --git a/hypothesis-python/src/hypothesis/internal/conjecture/choice.py b/hypothesis-python/src/hypothesis/internal/conjecture/choice.py index b536fa4ba5..5760f7c138 100644 --- a/hypothesis-python/src/hypothesis/internal/conjecture/choice.py +++ b/hypothesis-python/src/hypothesis/internal/conjecture/choice.py @@ -204,21 +204,19 @@ def choice_to_index(choice, kwargs): return 0 return int(choice) elif isinstance(choice, bytes): - index = collection_index( + return collection_index( list(choice), min_size=kwargs["min_size"], alphabet_size=2**8, ) - return index elif isinstance(choice, str): intervals = kwargs["intervals"] - index = collection_index( + return collection_index( choice, min_size=kwargs["min_size"], alphabet_size=len(intervals), to_order=intervals.index_from_char_in_shrink_order, ) - return index elif isinstance(choice, float): sign = int(sign_aware_lte(choice, -0.0)) return (sign << 64) | float_to_lex(abs(choice)) diff --git a/hypothesis-python/tests/conjecture/test_ir.py b/hypothesis-python/tests/conjecture/test_ir.py index 52cdfde931..e0c9a343f7 100644 --- a/hypothesis-python/tests/conjecture/test_ir.py +++ b/hypothesis-python/tests/conjecture/test_ir.py @@ -797,6 +797,8 @@ def test_choice_index_and_value_are_inverses(ir_type_and_kwargs): ("integer", integer_kw(max_value=5, shrink_towards=2), range(-10, 5 + 1)), ("integer", integer_kw(max_value=5), range(-10, 5 + 1)), ("integer", integer_kw(min_value=0, shrink_towards=1), range(10)), + ("integer", integer_kw(-5, 5, shrink_towards=3), range(-5, 5 + 1)), + ("integer", integer_kw(-5, 5, shrink_towards=-3), range(-5, 5 + 1)), ( "float", float_kw(1.0, next_up(next_up(1.0))),