-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix #11797: be more lenient on SequenceLike approx #11818
fix #11797: be more lenient on SequenceLike approx #11818
Conversation
2a16b61
to
79efc62
Compare
I'd go with the limited form only; we already treat lists and tuples as equal if their contents are approx-equal, so extending that to any sequence-like makes sense to me. We'll just want to be careful that the repr shows the original thing, and that self-containing sequences don't cause an infinite loop (they do now for list/tuple, but adding new types makes it more likely imo). |
@Zac-HD the repr from ApproxSequenceLike currently shows a list of approx in the repr instead of the original object as per pytest/src/_pytest/python_api.py Lines 315 to 320 in a3a2ffc
altering that part of the repr is something i consider out of scope for this fix |
Overall this looks good!
Which top level call you mean? |
Indeed, that's not so simple as might seem at first glance, because we cannot assume we can create arbitrary classes just by passing a sequence... a user might be using a custom class which is sequence-like, but we cannot assume we know/can create a new one from a sequence. |
@nicoddemus the call to the recursive map function - we have a coice between keeping certain custom types or not in its insides im currently not sure whether the caller should map over the sequence or the recursion should expand |
Is there any update on this PR or anything I could test or where I could contribute? |
changelog/11797.bugfix.rst
Outdated
@@ -0,0 +1 @@ | |||
Ensure approx for SequenceLike objects doesn't wrap those sequences in a scalar. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure approx for SequenceLike objects doesn't wrap those sequences in a scalar. | |
Ensure :func:`pytest.approx` for :class:`Sequence <collections.abc.Sequence>`-like objects does not wrap those sequences in a scalar. |
Or:
Ensure approx for SequenceLike objects doesn't wrap those sequences in a scalar. | |
:func:`pytest.approx` now correctly handles :class:`Sequence <collections.abc.Sequence>`-like objects. |
But then this feels more like an improvement than a bugfix? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll recategorize and rebase as soon as I get to it again
a3a2ffc
to
c8aa13c
Compare
this needs a validation as it allows partially implemented sequences
3a2d0bd
to
76f3f3d
Compare
this needs a validation as it allows partially implemented sequences
closes #11797
this changes the recursive map of approx to accept all sequences (just like approx)
i would like to gather feedback form @nicoddemus and @Zac-HD on whether to accept the recursion in general,
or if we ought to limit it by changing the toplevel call in ApproxSequenceLike to a listcomp operating only on the elements of the sequence