Fix 13010 - Ensure pytest.approx in sequence/collections only process instances of Number - #13012
Merged
nicoddemus merged 12 commits intoNov 30, 2024
Conversation
Add a check to ensure that `approx` calculations only process instances of `Number`, preventing errors with incompatible types.
for more information, see https://pre-commit.ci
nicoddemus
approved these changes
Nov 29, 2024
nicoddemus
left a comment
Member
There was a problem hiding this comment.
Thanks @marcelotrevisani for the PR, appreciated!
Left some small comments, other than that, LGTM.
nicoddemus
reviewed
Nov 29, 2024
Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
for more information, see https://pre-commit.ci
Contributor
Author
|
all done @nicoddemus ! |
Contributor
Author
|
I sorted all comments and problems. If you have new suggestions please let me know. Thanks! |
Member
|
FYI changed to a try/except instead of an instance check because mypy was correctly complaining about |
nicoddemus
enabled auto-merge (squash)
November 30, 2024 12:18
Contributor
Author
Indeed, I believe your modification is better, thanks! |
RonnyPfannschmidt
added a commit
to RonnyPfannschmidt/pytest
that referenced
this pull request
Sep 13, 2026
All three _repr_compare implementations seeded their running maxima with -math.inf and tested `== 0.0`, so building a failure message for Decimal collections compared a float against a Decimal. That comparison is exact, but it signals decimal.FloatOperation when that trap is set, and the two container variants handled the signal differently: - ApproxSequenceLike caught it. decimal.FloatOperation is a TypeError subclass, so the `except TypeError` added for pytest-dev#13012 to skip non-numbers swallowed it and the message reported `Max absolute difference: -inf`. - ApproxMapping did not, so it escaped out of the assertion formatting as a bare decimal.FloatOperation. Accumulate from None instead and only substitute -math.inf at the end, where it still means "no difference could be computed" as pytest-dev#13012 needs. Divide-by-zero is tracked as a flag rather than by assigning math.inf mid-loop, which would reintroduce the mixing on the next element. The sequence variant now re-raises decimal.FloatOperation explicitly, so a future float leak fails loudly instead of reporting -inf. Co-Authored-By: Claude Opus 5 (1M context) via Claude Code <noreply@anthropic.com>
RonnyPfannschmidt
added a commit
to RonnyPfannschmidt/pytest
that referenced
this pull request
Sep 13, 2026
All three _repr_compare implementations seeded their running maxima with -math.inf and tested `== 0.0`, so building a failure message for Decimal collections compared a float against a Decimal. That comparison is exact, but it signals decimal.FloatOperation when that trap is set, and the two container variants handled the signal differently: - ApproxSequenceLike caught it. decimal.FloatOperation is a TypeError subclass, so the `except TypeError` added for pytest-dev#13012 to skip non-numbers swallowed it and the message reported `Max absolute difference: -inf`. - ApproxMapping did not, so it escaped out of the assertion formatting as a bare decimal.FloatOperation. Accumulate from None instead and only substitute -math.inf at the end, where it still means "no difference could be computed" as pytest-dev#13012 needs. Divide-by-zero is tracked as a flag rather than by assigning math.inf mid-loop, which would reintroduce the mixing on the next element. The sequence variant now re-raises decimal.FloatOperation explicitly, so a future float leak fails loudly instead of reporting -inf. Co-Authored-By: Claude Opus 5 (1M context) via Claude Code <noreply@anthropic.com>
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.
#13010
Add a check to ensure that
approxcalculations only process instances ofNumber, preventing errors with incompatible types.