From fb4354d6292590163595840358c50493a8b5fe43 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 27 Aug 2021 16:37:08 -0400 Subject: [PATCH] Add type annots to calcs --- piker/calc.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/piker/calc.py b/piker/calc.py index 0f6d0e72..12fe0d79 100644 --- a/piker/calc.py +++ b/piker/calc.py @@ -21,7 +21,10 @@ import math import itertools -def humanize(number, digits=1): +def humanize( + number: float, + digits: int = 1 +) -> str: '''Convert large numbers to something with at most ``digits`` and a letter suffix (eg. k: thousand, M: million, B: billion). @@ -46,10 +49,17 @@ def humanize(number, digits=1): ) -def percent_change(init, new): - """Calcuate the percentage change of some ``new`` value +def percent_change( + + init: float, + new: float, + +) -> float: + '''Calcuate the percentage change of some ``new`` value from some initial value, ``init``. - """ + + ''' if not (init and new): return 0 + return (new - init) / init * 100.