pytest
pytest copied to clipboard
fix #11797: be more lenient on SequenceLike approx
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
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 https://github.com/pytest-dev/pytest/blob/a3a2ffcd163fe25506d828485d1267e99e223ecf/src/_pytest/python_api.py#L315-L320
altering that part of the repr is something i consider out of scope for this fix
Overall this looks good!
if we ought to limit it by changing the toplevel call in ApproxSequenceLike to a listcomp operating only on the elements of the sequence
Which top level call you mean?
altering that part of the repr is something i consider out of scope for this fix
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?