From 8bad2861faf30644afe52169cc8b940b510eabd1 Mon Sep 17 00:00:00 2001 From: Sebastian Kloth Date: Tue, 26 Dec 2023 11:33:59 +0100 Subject: [PATCH] Updated doc strings and added type hints --- src/mdevaluate/checksum.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/mdevaluate/checksum.py b/src/mdevaluate/checksum.py index a10ad3f..8a234eb 100755 --- a/src/mdevaluate/checksum.py +++ b/src/mdevaluate/checksum.py @@ -3,6 +3,7 @@ import hashlib from .logging import logger from types import ModuleType, FunctionType import inspect +from typing import Iterable import numpy as np @@ -11,7 +12,7 @@ import numpy as np SALT = 42 -def version(version_nr, calls=[]): +def version(version_nr: int, calls: Iterable = ()): """Function decorator that assigns a custom checksum to a function.""" def decorator(func): @@ -27,7 +28,7 @@ def version(version_nr, calls=[]): return decorator -def strip_comments(s): +def strip_comments(s: str): """Strips comment lines and docstring from Python source string.""" o = "" in_docstring = False @@ -43,14 +44,15 @@ def checksum(*args, csum=None): """ Calculate a checksum of any object, by sha1 hash. - Input for the hash are some salt bytes and the byte encoding of a string + Inputs for the hash are some salt bytes and the byte encoding of a string that depends on the object and its type: - - If a method __checksum__ is available, it's return value is converted to bytes + - If a method __checksum__ is available, its return value is converted to bytes - str or bytes are used as sha1 input directly - modules use the __name__ attribute - functions use the function code and any closures of the function - - functools.partial uses the checksum of the function and any arguments, that were defined + - functools.partial uses the checksum of the function and any arguments, that were + defined - numpy.ndarray uses bytes representation of the array (arr.tobytes()) - Anything else is converted to a str """