Updated doc strings and added type hints
This commit is contained in:
parent
aca9ba0723
commit
8bad2861fa
@ -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
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user