Hash and compare a wrapped object by identity instead of value
| 2062 | |
| 2063 | |
| 2064 | class _HashIdWrapper: |
| 2065 | """Hash and compare a wrapped object by identity instead of value""" |
| 2066 | |
| 2067 | def __init__(self, wrapped): |
| 2068 | self.wrapped = wrapped |
| 2069 | |
| 2070 | def __eq__(self, other): |
| 2071 | if not isinstance(other, _HashIdWrapper): |
| 2072 | return NotImplemented |
| 2073 | return self.wrapped is other.wrapped |
| 2074 | |
| 2075 | def __ne__(self, other): |
| 2076 | if not isinstance(other, _HashIdWrapper): |
| 2077 | return NotImplemented |
| 2078 | return self.wrapped is not other.wrapped |
| 2079 | |
| 2080 | def __hash__(self): |
| 2081 | return id(self.wrapped) |
| 2082 | |
| 2083 | |
| 2084 | @functools.lru_cache |
no outgoing calls
no test coverage detected
searching dependent graphs…