sourcery
sourcery copied to clipboard
Unecessary None checking
Issue description or question
I noticed a unnecessary None checking that could be simplified:
from typing import List, Optional
def func(items: Optional[List]):
if items is not None and isinstance(items, list):
return items.pop()
return None
Here checking for None is unnecessary, since NoneType != list.
Sourcery Version
0.8.2
Code editor or IDE name and version
Discovered on NeoVim 0.5.0
OS name and version
Ubuntu 20.04 via WSL
I guess in this case I would probably change it to:
if items:
return items.pop()
return None
but I don't think I could add that to Sourcery since the semantics aren't quite the same.
Maybe my example was not the best :)
I was focusing in the fact that the items is not of type list (I'm using list in the example but it could be any other type/class) when it is None, and vice-versa (tautology).
It is more evident if the conditional is switched around:
def func(items: Optional[List]):
if isinstance(items, list) and items is not None
# some code
#other code
Yes I see what you mean - have added it to our pipeline.