Expression can be simplified on list

Steve D'Aprano steve+python at pearwood.info
Thu Sep 29 20:24:31 EDT 2016


On Fri, 30 Sep 2016 05:58 am, Random832 wrote:

> On Thu, Sep 29, 2016, at 02:47, Rustom Mody wrote:
>> Your example is exactly what I am saying; if a type has a behavior in
>> which all values are always True (true-ish) its a rather strange kind
>> of bool-nature.
> 
> For a given type T, if all objects of type T are true (true-ish, truthy,
> whatever), it does make using an expression of type T in an if-statement
> an incoherent thing to do, but it makes using an expression of type
> Union[T, NoneType] reasonable.


Or Union[T, S] where S is some other type (including a union of multiple
types) which has at least one falsey value.




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list