Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I do a conditional yield with Python?

I have to refactor some code. The original code was something like:

 while (yield _requires_payment(state)):
        did_pass_limit = yield _did_pass_limit(state)
        if not did_pass_limit:
            if existing_count is None:
                yield send_info_log("some stuff")
            yield send_info_log(f"more stuff")

So I refactored to:

    if yield _requires_payment(state):
        yield send_info_log(f"stuff")

If it matters, the function definition is:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@dialog(version="1.0")
async def _requires_payment(state):
    return await apply_payment_status_check(state, check_types=["window"])

But this creates an issue. What am I doing wrong?

>Solution :

If you want to use yield as an expression, surround it with parentheses. Just like it was in your while condition.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading