79329775

Date: 2025-01-04 23:31:49
Score: 0.5
Natty:
Report link

I'd solve this by placing a yield from expression outside the loop:

def iterate_my_objects_if_something(self):
    for x in self.my_objects:
        if x.something:
            yield x
    yield from []

This results in an iterable, without adding unwanted additional elements to be yielded.

Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: elias