diff options
author | Hernan <hernan.grecco@gmail.com> | 2019-12-28 02:09:07 -0300 |
---|---|---|
committer | Hernan <hernan.grecco@gmail.com> | 2019-12-28 02:09:07 -0300 |
commit | e51af44fc38bc43a03bac8685ed845d1beca0e20 (patch) | |
tree | f939bfd7d7027b1639a58b8086c9d15d75b523fd | |
parent | a08fda75a0162b35d0a6864150b063eea15f36b8 (diff) | |
download | pint-e51af44fc38bc43a03bac8685ed845d1beca0e20.tar.gz |
Add verification of number of args/params in check and wrap
-rw-r--r-- | pint/registry_helpers.py | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/pint/registry_helpers.py b/pint/registry_helpers.py index d51daba..c9dde57 100644 --- a/pint/registry_helpers.py +++ b/pint/registry_helpers.py @@ -214,6 +214,14 @@ def wraps(ureg, ret, args, strict=True): container, ret = False, _to_units_container(ret, ureg) def decorator(func): + + count_params = len(signature(func).parameters) + if len(args) != count_params: + raise TypeError( + "%s takes %i parameters, but %i units were passed" + % (func.__name__, count_params, len(args)) + ) + assigned = tuple( attr for attr in functools.WRAPPER_ASSIGNMENTS if hasattr(func, attr) ) @@ -287,6 +295,14 @@ def check(ureg, *args): ] def decorator(func): + + count_params = len(signature(func).parameters) + if len(dimensions) != count_params: + raise TypeError( + "%s takes %i parameters, but %i dimensions were passed" + % (func.__name__, count_params, len(dimensions)) + ) + assigned = tuple( attr for attr in functools.WRAPPER_ASSIGNMENTS if hasattr(func, attr) ) @@ -297,11 +313,7 @@ def check(ureg, *args): @functools.wraps(func, assigned=assigned, updated=updated) def wrapper(*args, **kwargs): list_args, empty = _apply_defaults(func, args, kwargs) - if len(dimensions) > len(list_args): - raise TypeError( - "%s takes %i parameters, but %i dimensions were passed" - % (func.__name__, len(list_args), len(dimensions)) - ) + for dim, value in zip(dimensions, list_args): if dim is None: |