-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Ensure regen utility class gets marked as done when concretised #6789
Conversation
Codecov Report
@@ Coverage Diff @@
## master #6789 +/- ##
=======================================
Coverage 70.69% 70.70%
=======================================
Files 138 138
Lines 16602 16601 -1
Branches 2091 2093 +2
=======================================
Hits 11737 11737
+ Misses 4669 4668 -1
Partials 196 196
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
t/unit/utils/test_functional.py
Outdated
g = regen(die()) | ||
assert "..." in repr(g) | ||
|
||
@pytest.mark.xfail(raises=StopIteration, reason="XXX NEEDS AN ISSUE") |
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.
This test is for an edge case where a repeatable iterator could raise an exception at some point before completion which would result in regen()
stashing the elements it saw but never marking itself as done. Then the next time we yield elements from an iterator derived from the regen()
instance, we'd yield the stashed elements, then repeat them from the underlying iterator if it's capable of giving them to us again.
IDK if this is something we can even bother handling. If the underlying iterator explodes, we could choose to mark the regen instance as __done
and just give up on attempting to get more elements? If we want to go down that route, I can roll a change into this PR since it'd be pretty simple and still thematically relevant. If we think we need to do something more involved or optimistic, I'll make a follow up issue for discussion.
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've made #6794 to track the discussion on this point. Could just be a thing we need to document, happy to have this PR merged without addressing that issue yet.
This pull request fixes 1 alert when merging 42685f2 into c93371d - view on LGTM.com fixed alerts:
|
Good question. That was added in 9982773 and looks like it could have been deliberate, but I have no idea why that might be the case. AFAICT you'd have to be raising Removing the |
eaca2b6
to
9852391
Compare
This pull request introduces 2 alerts when merging 9852391 into b0ebc3b - view on LGTM.com new alerts:
|
Since Python 3.7 raising |
This is probably an oversight we made during the Python 3 only migration in 5.0. |
This ensures that the generator remains lazy if it's passed to `repr()`, e.g. for logging or something.
d419012
to
64da3e8
Compare
I just pushed a change which removed what I thought was a pointless Edit: I spent some more time on this and have an improved implementation but some of the tests aren't playing nice with it. For the moment, I'm going to call this changeset done and ready for a review prior to merge |
This pull request introduces 1 alert and fixes 1 when merging 64da3e8 into 799f839 - view on LGTM.com new alerts:
fixed alerts:
|
I wonder how much use that |
I'd guess the only time it really gets called is to access the 0th or |
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.
let's merge it after some 5.1.x point releases
I think we can include it in 5.1.1 unless there's a special reason not to do so that I missed. |
OK. merged as bugfix |
* fix: `regen.data` property now marks self as done Fixes: #6786 * improv: Don't concretise regen on `repr()` This ensures that the generator remains lazy if it's passed to `repr()`, e.g. for logging or something. * test: Add failing test for regen duping on errors * refac: Remove unnecessary try in `regen.data`
…ry#6789) * fix: `regen.data` property now marks self as done Fixes: celery#6786 * improv: Don't concretise regen on `repr()` This ensures that the generator remains lazy if it's passed to `repr()`, e.g. for logging or something. * test: Add failing test for regen duping on errors * refac: Remove unnecessary try in `regen.data`
Description
Ensure
regen()
instances get marked as done when concretised via theUserList.data
property implementation. We also improve laziness ofregen.__repr__()
so it reflects the fact that it's lazy.Fixes: #6786