Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enforce ignore default values #70

Open
yitai27 opened this issue Apr 24, 2018 · 0 comments
Open

enforce ignore default values #70

yitai27 opened this issue Apr 24, 2018 · 0 comments

Comments

@yitai27
Copy link

yitai27 commented Apr 24, 2018

from typing import NamedTuple
from enforce import runtime_validation

@runtime_validation
class ArpEntry(NamedTuple):
    mac: str
    ip: str
    iface : str = None
>>> ArpEntry(mac='00:11:22:33:44:55', ip='1.1.1.1', iface='asdf')
ArpEntry(mac='00:11:22:33:44:55', ip='1.1.1.1', iface='asdf')
>>> ArpEntry(mac='00:11:22:33:44:55', ip='1.1.1.1')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/junk/cortex/venv/lib/python3.6/site-packages/enforce/decorators.py", line 188, in __call__
    data = init_data(*args, **kwargs)
  File "/home/user/junk/cortex/venv/lib/python3.6/site-packages/wrapt/wrappers.py", line 523, in __call__
    args, kwargs)
  File "/home/user/junk/cortex/venv/lib/python3.6/site-packages/enforce/decorators.py", line 104, in universal
    _args, _kwargs, _ = enforcer.validate_inputs(parameters)
  File "/home/user/junk/cortex/venv/lib/python3.6/site-packages/enforce/enforcers.py", line 71, in validate_inputs
    binded_arguments = self.signature.bind(*args, **kwargs)
  File "/usr/lib/python3.6/inspect.py", line 2969, in bind
    return args[0]._bind(args[1:], kwargs)
  File "/usr/lib/python3.6/inspect.py", line 2940, in _bind
    format(arg=param_name)) from None
TypeError: missing a required argument: 'iface'

Without enforce, I can create ArpEntry with only mac and ip, but with enforce I get TypeError.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant