Skip to content

Instantly share code, notes, and snippets.

@gidgid
Created December 13, 2020 19:45
Show Gist options
  • Save gidgid/d5cb88608e03a4a2fb90ce8da27a98c6 to your computer and use it in GitHub Desktop.
Save gidgid/d5cb88608e03a4a2fb90ce8da27a98c6 to your computer and use it in GitHub Desktop.
from abc import ABC, abstractmethod
from dataclasses import dataclass
class Bool(ABC):
@abstractmethod
def __bool__(self):
"""True/False depends on the type"""
@dataclass
class Truthy(Bool):
def __bool__(self):
return True
@dataclass
class Falsy(Bool):
def __bool__(self):
return False
def test_true_and_false():
assert bool(Truthy()) is True
assert bool(Falsy()) is False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment