-
Notifications
You must be signed in to change notification settings - Fork 5
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: InsertValue will error if input
is None
#18
Fix: InsertValue will error if input
is None
#18
Conversation
9da517d
to
ebfc6c9
Compare
ebfc6c9
to
14176ba
Compare
Ok, so, interesting... My original intended use case for InsertValue assumes that it will receive further values, in other words it was supposed to not be used as the first section and thus would always get an input. I was never really intending it to be used as first section. Naively I actually expected that this might cause bad things to happen, like the pipeline might hang after single value was emitted, because there wasn't a source stream to exhaust of values. But, luckily the weld function actually knows how to handle this situation and will simply close the output memory channel, once the pump function exits, if there is no input. So, this turns out to be safe. I think there should be a test for this. Maybe:
And maybe a tiny note should be added to the documentation specifying the expected behaviour for this corner case. |
I kinda figured, but the type annotation says it's optional, so either the no-input case should be handled or the type annotation should be fixed. The latter opens its own can of worms because we'd then be overriding
Heh, this PR already contains one. Funnily enough, our test implementations are identical, except for the name and the fact that I used async def test_insert_value_no_input(autojump_clock):
async with Pipeline.create(
InsertValue('n')
) as pipeline, pipeline.tap() as aiter:
results = [v async for v in aiter]
assert results == ['n']
Good call. I'll add something. |
@andersea Looking at the docs, I noticed that all other sections that can be used as starting sections say "can be used as a starting section, if a source is provided." Should we add support for a |
@mikenerone Ok, I got through the review. Looks good. I haven't used the monkeypatch module, but I see how it helps a lot in this case. But I had to go through everything step by step to make sure I understood what was going on. If you want to add an optional source parameter to InsertValue, go ahead. I am fine with it either way. |
Sorry for the delay, I'll get to it eventually. :P |
@andersea Ok, ready now. In the end I felt like the |
Thank you! |
Title says most of it. Related, Metronome handled the no input case correctly, but there wasn't a test for it, so I added one for that, too. I also took the liberty of making the
Metronome
tests fast withautojump_clock
, if that's ok (they were the only ones that slowed the test run).