Created
January 16, 2022 08:50
-
-
Save mawillcockson/38e95a427e16344de3afc5cc1c26b5ea to your computer and use it in GitHub Desktop.
Whatever it is you're looking for, this is not it
This file contains 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
_hash = 0 | |
class Falsey: | |
def __init__(self, *args, **kwargs): pass | |
# comparisons | |
def __lt__(self, other): return False | |
def __le__(self, other): return False | |
def __eq__(self, other): return False | |
def __ne__(self, other): return False | |
def __gt__(self, other): return False | |
def __ge__(self, other): return False | |
def __not__(self, other): return False | |
# representation | |
def __bool__(self): return False | |
def __str__(self): return "" | |
def __repr__(self): return "" | |
def __float__(self): return 0.0 | |
def __len__(self): return 0 | |
def __contains__(self, other): return False | |
def __hash__(self): | |
global _hash | |
_hash += 1 | |
return _hash | |
def __format__(self, format_spec): return "" | |
def __bytes__(self): return b"" | |
# attribute/item access | |
def __getattribute__(self, name): return Falsey() | |
def __dir__(self): return () | |
def __getitem__(self, key): return Falsey() | |
def __class_getitem__(cls, key): return Falsey() | |
# math | |
def __add__(self, other): return self | |
def __sub__(self, other): return self | |
def __mul__(self, other): return self | |
def __matmul__(self, other): return self | |
def __truediv__(self, other): return self | |
def __floordiv__(self, other): return self | |
def __mod__(self, other): return self | |
def __divmod__(self, other): return self | |
def __pow__(self, other, modulo=0): return self | |
def __lshift__(self, other): return self | |
def __rshift__(self, other): return self | |
def __and__(self, other): return self | |
def __xor__(self, other): return self | |
def __or__(self, other): return self | |
def __radd__(self, other): return self | |
def __rsub__(self, other): return self | |
def __rmul__(self, other): return self | |
def __rmatmul__(self, other): return self | |
def __rtruediv__(self, other): return self | |
def __rfloordiv__(self, other): return self | |
def __rmod__(self, other): return self | |
def __rdivmod__(self, other): return self | |
def __rpow__(self, other, modulo=0): return self | |
def __rlshift__(self, other): return self | |
def __rrshift__(self, other): return self | |
def __rand__(self, other): return self | |
def __rxor__(self, other): return self | |
def __ror__(self, other): return self | |
def __iadd__(self, other): return self | |
def __isub__(self, other): return self | |
def __imul__(self, other): return self | |
def __imatmul__(self, other): return self | |
def __itruediv__(self, other): return self | |
def __ifloordiv__(self, other): return self | |
def __imod__(self, other): return self | |
def __ipow__(self, other, modulo=0): return self | |
def __ilshift__(self, other): return self | |
def __irshift__(self, other): return self | |
def __iand__(self, other): return self | |
def __ixor__(self, other): return self | |
def __ior__(self, other): return self | |
# unary math | |
def __neg__(self): return 0 | |
def __pos__(self): return 0 | |
def __abs__(self): return 0 | |
def __invert__(self): return 0 | |
def __round__(self, ndigits=0): return 0 | |
def __trunc__(self): return 0 | |
def __floor__(self): return 0 | |
def __ceil__(self): return 0 | |
# other | |
def __call__(self, *args, **kwargs): return self | |
if __name__ == "__main__": | |
falsey = Falsey() | |
assert not falsey | |
assert not Falsey[False] | |
assert not falsey[falsey] | |
assert not falsey(falsey) | |
assert not str(falsey) | |
assert not int(falsey) | |
assert not float(falsey) | |
assert not complex(falsey) | |
assert not repr(falsey) | |
assert not falsey < falsey | |
assert not falsey <= falsey | |
assert not falsey == falsey | |
assert not falsey != falsey | |
assert not falsey > falsey | |
assert not falsey >= falsey | |
assert not falsey in falsey | |
assert not hash(falsey) == hash(falsey) | |
assert not falsey.false | |
assert not falsey + falsey - falsey | |
assert not falsey * 2 + 100 | |
assert not falsey ^ falsey | |
assert not falsey ** falsey | |
assert falsey is falsey # :( | |
assert hasattr(falsey, "false") # :( | |
assert not isinstance(falsey, Falsey) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can definitely be more falsey.