Skip to content

Commit 08f6bbb

Browse files
DRMacIverclaude
andcommitted
Drop unreachable defensive branches from _natural_simpler_chars
The pass only calls this helper for characters that come from a string choice node's value (so always single-char and always in the alphabet), and unicodedata.normalize never returns an empty string for non-empty input - so the length / empty-decomposition guards and the two ValueError fallbacks were dead code keeping coverage from reaching 100%. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 4082379 commit 08f6bbb

1 file changed

Lines changed: 10 additions & 26 deletions

File tree

  • hypothesis-python/src/hypothesis/internal/conjecture

hypothesis-python/src/hypothesis/internal/conjecture/shrinker.py

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -97,37 +97,21 @@ def _natural_simpler_chars(c, intervals):
9797
9898
Only candidates which are in ``intervals`` and which have a strictly
9999
smaller index in shrink order than ``c`` are returned, sorted by that
100-
shrink-order index.
100+
shrink-order index. Callers must pass a single character that is itself
101+
in ``intervals``.
101102
"""
102-
if len(c) != 1:
103-
return []
104-
candidates = set()
103+
candidates = {unicodedata.normalize(form, c)[0] for form in ("NFKD", "NFD")}
105104
for transformed in (c.upper(), c.lower(), c.casefold()):
106105
if len(transformed) == 1:
107106
candidates.add(transformed)
108-
for form in ("NFKD", "NFD"):
109-
decomp = unicodedata.normalize(form, c)
110-
if decomp:
111-
candidates.add(decomp[0])
112107
candidates.discard(c)
113-
if not candidates:
114-
return []
115-
try:
116-
original_idx = intervals.index_from_char_in_shrink_order(c)
117-
except ValueError:
118-
return []
119-
result = []
120-
for cand in candidates:
121-
if cand not in intervals:
122-
continue
123-
try:
124-
cand_idx = intervals.index_from_char_in_shrink_order(cand)
125-
except ValueError:
126-
continue
127-
if cand_idx < original_idx:
128-
result.append((cand_idx, cand))
129-
result.sort()
130-
return [c for _, c in result]
108+
original_idx = intervals.index_from_char_in_shrink_order(c)
109+
result = sorted(
110+
(intervals.index_from_char_in_shrink_order(cand), cand)
111+
for cand in candidates
112+
if cand in intervals
113+
)
114+
return [cand for idx, cand in result if idx < original_idx]
131115

132116

133117
@dataclass(slots=True, frozen=False)

0 commit comments

Comments
 (0)