def function_digest(function): """Returns a string that is stable across multiple invocations across multiple processes and is prone to changing significantly in response to minor changes to the function. No guarantee of uniqueness though it usually will be. """ hasher = hashlib.md5() try: hasher.update(to_unicode(inspect.getsource(function)).encode(u'utf-8')) # Different errors on different versions of python. What fun. except (OSError, IOError, TypeError): pass try: hasher.update(function.__name__.encode(u'utf-8')) except AttributeError: pass try: hasher.update(function.__module__.__name__.encode(u'utf-8')) except AttributeError: pass try: hasher.update(repr(getargspec(function)).encode(u'utf-8')) except TypeError: pass return hasher.digest()
def function_digest(function): """Returns a string that is stable across multiple invocations across multiple processes and is prone to changing significantly in response to minor changes to the function. No guarantee of uniqueness though it usually will be. """ hasher = hashlib.md5() try: hasher.update(to_unicode(inspect.getsource(function)).encode('utf-8')) # Different errors on different versions of python. What fun. except (OSError, IOError, TypeError): pass try: hasher.update(str_to_bytes(function.__name__)) except AttributeError: pass try: hasher.update(function.__module__.__name__.encode('utf-8')) except AttributeError: pass try: hasher.update(str_to_bytes(repr(getfullargspec(function)))) except TypeError: pass return hasher.digest()
def function_digest(function): """Returns a string that is stable across multiple invocations across multiple processes and is prone to changing significantly in response to minor changes to the function. No guarantee of uniqueness though it usually will be. """ hasher = hashlib.sha384() try: hasher.update(to_unicode(inspect.getsource(function)).encode("utf-8")) except (OSError, TypeError): pass try: hasher.update(str_to_bytes(function.__name__)) except AttributeError: pass try: hasher.update(function.__module__.__name__.encode("utf-8")) except AttributeError: pass try: hasher.update(str_to_bytes(repr(inspect.getfullargspec(function)))) except TypeError: pass try: hasher.update(function._hypothesis_internal_add_digest) except AttributeError: pass return hasher.digest()