diff options
author | F. Eugene Aumson <feuGeneA@users.noreply.github.com> | 2018-10-24 00:08:16 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-24 00:08:16 +0800 |
commit | 1f0c7f8fbeba90ac1f65c57ff58782051c751b3d (patch) | |
tree | c5239e139729d6e4e63454c24679e8559f7c7560 /python-packages/order_utils/src/zero_ex/dev_utils/type_assertions.py | |
parent | 1ba207f1fef4338682b4cc7e45af8c073e63d263 (diff) | |
download | dexon-sol-tools-1f0c7f8fbeba90ac1f65c57ff58782051c751b3d.tar dexon-sol-tools-1f0c7f8fbeba90ac1f65c57ff58782051c751b3d.tar.gz dexon-sol-tools-1f0c7f8fbeba90ac1f65c57ff58782051c751b3d.tar.bz2 dexon-sol-tools-1f0c7f8fbeba90ac1f65c57ff58782051c751b3d.tar.lz dexon-sol-tools-1f0c7f8fbeba90ac1f65c57ff58782051c751b3d.tar.xz dexon-sol-tools-1f0c7f8fbeba90ac1f65c57ff58782051c751b3d.tar.zst dexon-sol-tools-1f0c7f8fbeba90ac1f65c57ff58782051c751b3d.zip |
feat(order_utils.py): ERC20 asset data encoding and decoding
In addition to the ERC20 codec, also:
Stopped ignoring type errors on 3rd party imports, by including
interface stubs for them;
Removed the unimplemented signature-utils module, which was just a
stand-in when the python project support was first put in place.
https://github.com/0xProject/0x-monorepo/pull/1144
Diffstat (limited to 'python-packages/order_utils/src/zero_ex/dev_utils/type_assertions.py')
-rw-r--r-- | python-packages/order_utils/src/zero_ex/dev_utils/type_assertions.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/python-packages/order_utils/src/zero_ex/dev_utils/type_assertions.py b/python-packages/order_utils/src/zero_ex/dev_utils/type_assertions.py new file mode 100644 index 000000000..745d014e6 --- /dev/null +++ b/python-packages/order_utils/src/zero_ex/dev_utils/type_assertions.py @@ -0,0 +1,33 @@ +"""Assertions for runtime type checking of function arguments.""" + +from typing import Any + + +def assert_is_string(value: Any, name: str) -> None: + """If :param value: isn't of type str, raise a TypeError. + + >>> try: assert_is_string(123, 'var') + ... except TypeError as type_error: print(str(type_error)) + ... + expected variable 'var', with value 123, to have type 'str', not 'int' + """ + if not isinstance(value, str): + raise TypeError( + f"expected variable '{name}', with value {str(value)}, to have" + + f" type 'str', not '{type(value).__name__}'" + ) + + +def assert_is_list(value: Any, name: str) -> None: + """If :param value: isn't of type list, raise a TypeError. + + >>> try: assert_is_list(123, 'var') + ... except TypeError as type_error: print(str(type_error)) + ... + expected variable 'var', with value 123, to have type 'list', not 'int' + """ + if not isinstance(value, list): + raise TypeError( + f"expected variable '{name}', with value {str(value)}, to have" + + f" type 'list', not '{type(value).__name__}'" + ) |