Skip to content

Instantly share code, notes, and snippets.

@aodag
Last active July 9, 2018 02:30
Show Gist options
  • Save aodag/8dee67b261d21cd209b8f89bf87db087 to your computer and use it in GitHub Desktop.
Save aodag/8dee67b261d21cd209b8f89bf87db087 to your computer and use it in GitHub Desktop.
"""
>>> v = {"a": 1, "b": 2}
>>> assert v == {"a": 1, "b": Any()}
>>> assert v == {"a": 1, "b": IsA(int)}
"""
class Any:
def __eq__(self, o):
return True
class NotNone:
def __eq__(self, o):
return o is not None
class IsTrue:
def __eq__(self, o):
return bool(o)
class IsA:
def __init__(self, typ):
self.typ = typ
def __eq__(self, o):
return isinstance(o, self.typ)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment