Nathan West added the comment:
Doesn't the same issue exist for all other uses of the idiom, though?
Python provides container "truthiness" even though `len(x) == 0` is more
"correct."
On Fri, Jun 5, 2015, 3:20 PM Yury Selivanov wrote:
>
> Yury Selivanov added the comment:
>
> Nathan, consider
Yury Selivanov added the comment:
Nathan, consider the following signature:
def foo(a=0:''): pass
now, sig.parameters['a'].annotation will be '' and .default will be 0, and they
will fail 'if param.annotation or param.default' check. That's why we
encourage checks like 'if param.annotation
New submission from Nathan West:
A common Python idiom is to test objects by value in an if. This includes
container emptiness and regular expression matches, or using 'or' to specify a
default value:
if my_list:
# list isn't empty
if regex.match(string):
# string match