This is a most excellent place for technology news and articles.
That's just not true:
not x
[]
{}
len(x) == 0
list
dict
tuple
__len__
You can probably assume it's iterable, but that's about it.
But why assume? You can easily just document the type with a type-hint:
def do_work(foo: list | None): if not foo: return ...
That's just not true:
not x
- has an empty value (None, False,[]
,{}
, etc)len(x) == 0
- has a length (list
,dict
,tuple
, etc, or even a custom type implementing__len__
)You can probably assume it's iterable, but that's about it.
But why assume? You can easily just document the type with a type-hint: