Skip to content

Instantly share code, notes, and snippets.

@taddeimania
Last active January 7, 2022 22:49
Show Gist options
  • Save taddeimania/308ef82a450729fa2e89 to your computer and use it in GitHub Desktop.
Save taddeimania/308ef82a450729fa2e89 to your computer and use it in GitHub Desktop.
Proposal for Maybe type in python (True OR False)
import ast
import random
class MaybeType(type):
def __repr__(cls):
return str(bool(random.randint(0, 1)))
def __nonzero__(cls):
return ast.literal_eval(repr(cls))
class Maybe(object):
__metaclass__ = MaybeType
>>> Maybe
True
>>> Maybe
True
>>> Maybe
False
>>> bool(Maybe)
False
>>> bool(Maybe)
True
>>> True = Maybe # import chaos
>>> True
True
>>> True
True
>>> True
False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment