Skip to content

Commit ba34e6f

Browse files
committed
Narrow mapping to dict for FixedDictStrategy in fixed_dictionaries
The public signature is now Mapping (covariant), but FixedDictStrategy requires a concrete dict, which check_type already guarantees at runtime. Cast to satisfy the package-wide mypy check. https://claude.ai/code/session_01GGWSpKXv1sihrTexfxyxBo
1 parent ffd60aa commit ba34e6f

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

  • hypothesis/src/hypothesis/strategies/_internal

hypothesis/src/hypothesis/strategies/_internal/core.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,12 @@ def fixed_dictionaries(
584584
f"which is invalid: {set(mapping) & set(optional)!r}"
585585
)
586586

587-
return FixedDictStrategy(mapping, optional=optional)
587+
# check_type above guarantees both are dicts at runtime, but the public
588+
# signature is Mapping (covariant) so we narrow for FixedDictStrategy here.
589+
return FixedDictStrategy(
590+
cast(dict[Any, SearchStrategy[Any]], mapping),
591+
optional=cast(dict[Any, SearchStrategy[Any]] | None, optional),
592+
)
588593

589594

590595
_get_first_item = operator.itemgetter(0)

0 commit comments

Comments
 (0)