In general, let\'s say you have a method like the below.
def intersect_two_lists(self, list1, list2):
if not list1:
self.trap_e
For collections (lists, sets, dicts, etc.) returning an empty collection is the obvious choice because it allows your call site logic to remain clear of defensive logic. More explicitly, an empty collection is still a perfectly good answer from a function from which you expect a collection, you do not have to check that the result is of any other type, and can continue your business logic in a clean manner.
For non collection results there are several ways to handle conditional returns:
None instead of your expected result but this forces a user to add defensive checks everywhere in their call sites, obfuscating the actual business logic they are trying to actually execute.pip install optional.py. I welcome comments, feature requests, and contributions.