Suppose I want to run some code for each element in an iterable, but if there are none, run once for the value of None. However, the natural code
def f(some_iterable):
for x in [*some_iterable] or [None]:
do_something(x)
fails SIM222, which wants to remove the or [None] part, presumably thinking the list will always be truthy. Similarly to #9479, the rule needs to take into account that a list/set/dict literal containing only *-elements can still end up empty.
Suppose I want to run some code for each element in an iterable, but if there are none, run once for the value of None. However, the natural code
fails SIM222, which wants to remove the
or [None]part, presumably thinking the list will always be truthy. Similarly to #9479, the rule needs to take into account that a list/set/dict literal containing only *-elements can still end up empty.