Add type annots to calcs

fsp_feeds
Tyler Goodlet 2021-08-27 16:37:08 -04:00
parent 3dd98ff56a
commit fb4354d629
1 changed files with 14 additions and 4 deletions

View File

@ -21,7 +21,10 @@ import math
import itertools 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 '''Convert large numbers to something with at most ``digits`` and
a letter suffix (eg. k: thousand, M: million, B: billion). a letter suffix (eg. k: thousand, M: million, B: billion).
@ -46,10 +49,17 @@ def humanize(number, digits=1):
) )
def percent_change(init, new): def percent_change(
"""Calcuate the percentage change of some ``new`` value
init: float,
new: float,
) -> float:
'''Calcuate the percentage change of some ``new`` value
from some initial value, ``init``. from some initial value, ``init``.
"""
'''
if not (init and new): if not (init and new):
return 0 return 0
return (new - init) / init * 100. return (new - init) / init * 100.