Fix type annotation to allow int keys in data_regression.check() #219
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.
Summary
The
DataRegressionFixture.check()method's type annotation was overly restrictive, only allowingdict[str, Any]when the documentation states it accepts "any yaml serializable dict". This PR updates the type annotation todict[str | int, Any]to allow integer keys.Motivation
Integer keys are commonly used in test data (e.g., for indexing test cases by number), and YAML fully supports them. Users currently have to convert int keys to strings unnecessarily to satisfy type checkers, even though the code works correctly at runtime.
Changes
src/pytest_regressions/data_regression.py:39fromdict[str, Any]todict[str | int, Any]test_integer_keys()test case demonstrating integer key supportType Choice Rationale
We chose
str | intrather than broader types because:trueand"true"Testing
The new test case
test_integer_keys()verifies that integer keys work correctly with the data regression fixture.Real-World Use Case
This fix enables code like: