aboutsummaryrefslogtreecommitdiffstats
path: root/utils/misc.py
diff options
context:
space:
mode:
authorShivesh Mandalia <shivesh.mandalia@outlook.com>2020-04-20 00:03:47 +0100
committerShivesh Mandalia <shivesh.mandalia@outlook.com>2020-04-20 00:03:47 +0100
commit1c8649fdcd9f56cca5b191ae3cbaec4977569380 (patch)
tree14299d85de895df774a5c2b5b44ee3d10e0f5f7f /utils/misc.py
parent92375e2d232538c72e9dfe7d6f067dfcc7e5979f (diff)
downloadMCOptionPricing-1c8649fdcd9f56cca5b191ae3cbaec4977569380.tar.gz
MCOptionPricing-1c8649fdcd9f56cca5b191ae3cbaec4977569380.zip
Linting, type checking
Diffstat (limited to 'utils/misc.py')
-rw-r--r--utils/misc.py36
1 files changed, 22 insertions, 14 deletions
diff --git a/utils/misc.py b/utils/misc.py
index 708d759..f7743d1 100644
--- a/utils/misc.py
+++ b/utils/misc.py
@@ -7,24 +7,31 @@
Miscellaneous utility methods.
"""
+from typing import Any, Union
-__all__ = ['is_num', 'is_pos']
+__all__ = ['Number', 'is_num', 'is_pos']
-def is_num(val: (int, float)) -> bool:
+
+_T = (int, float)
+Number = Union[int, float]
+
+
+def is_num(val: Any) -> bool:
"""
- Check if the input value is a non-infinite number.
+ Check if the input value is a finite number.
Parameters
----------
- val : Value to check.
+ val : object
+ Value to check.
Returns
- ----------
- is_num : Whether it is a non-infinite number.
+ -------
+ bool
Examples
- ----------
+ --------
>>> from utils.misc import is_num
>>> print(is_num(10))
True
@@ -32,25 +39,26 @@ def is_num(val: (int, float)) -> bool:
False
"""
- if not isinstance(val, (int, float)):
+ if not isinstance(val, _T):
return False
return True
-def is_pos(val: (int, float)) -> bool:
+def is_pos(val: Any) -> bool:
"""
- Check if the input value is a non-infinite positive number.
+ Check if the input value is a finite positive number.
Parameters
----------
- val : Value to check.
+ val : object
+ Value to check.
Returns
- ----------
- is_pos : Whether it is a non-infinite positive number.
+ -------
+ bool
Examples
- ----------
+ --------
>>> from utils.misc import is_pos
>>> print(is_pos(10))
True