Created
December 13, 2020 19:45
-
-
Save gidgid/d5cb88608e03a4a2fb90ce8da27a98c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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