You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
rdaysky
changed the title
SIM222 false positive in if [*iterable] or [another list]
SIM222 false positive in [*iterable] or [another list]Nov 10, 2024
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.The text was updated successfully, but these errors were encountered: