summaryrefslogtreecommitdiff
path: root/pint/registry_helpers.py
diff options
context:
space:
mode:
authorHernan <hernan.grecco@gmail.com>2019-12-28 02:09:07 -0300
committerHernan <hernan.grecco@gmail.com>2019-12-28 02:09:07 -0300
commite51af44fc38bc43a03bac8685ed845d1beca0e20 (patch)
treef939bfd7d7027b1639a58b8086c9d15d75b523fd /pint/registry_helpers.py
parenta08fda75a0162b35d0a6864150b063eea15f36b8 (diff)
downloadpint-e51af44fc38bc43a03bac8685ed845d1beca0e20.tar.gz
Add verification of number of args/params in check and wrap
Diffstat (limited to 'pint/registry_helpers.py')
-rw-r--r--pint/registry_helpers.py22
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: