return obj def __str__(self): return "~" + str(self.token) __repr__ = __str__ def __eq__(self, other): return type(self) == type(other) and self.token == other.token def __hash__(self): return hash((type(self), self.token)) var = lambda *args: Var(*args) vars = lambda n: [var() for i in range(n)] isvar = lambda t: (isinstance(t, Var) or (not not _glv and hashable(t) and t in _glv)) @contextmanager def variables(*variables): """ Context manager for logic variables >>> from __future__ import with_statement >>> from logpy.variables import variables, var, isvar >>> with variables(1): ... print isvar(1) True >>> print isvar(1) False Normal approach
def test_hashable(): assert hashable(2) assert hashable((2,3)) assert not hashable({1: 2}) assert not hashable((1, {2: 3}))