[Python-ideas] Maybe/Option builtin

Jonas Wielicki j.wielicki at sotecware.net
Wed May 21 17:16:17 CEST 2014


On 21.05.2014 16:49, mulhern wrote:
> Something like:
> 
> class Maybe(object):
> 
>     def __init__(self, value=None):
>         self.value = value
> 
>     def value(self):
>         return self.value
> 
> is a start but I'm not able to see how to make
> 
> if Maybe():
>     print("nothing") # never prints
> 
> but
> 
> if Maybe({}):
>     print("yes a value") #always prints

Implement the __bool__ method:
<https://docs.python.org/3/reference/datamodel.html#object.__bool__>.

I don’t have any opinion on the proposal itself.

regards,
Jonas


More information about the Python-ideas mailing list