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

guard don't work correct with keyword-only arguments and default value #122

Open
Arfey opened this issue Mar 31, 2022 · 3 comments
Open

Comments

@Arfey
Copy link
Collaborator

Arfey commented Mar 31, 2022

import trafaret as trf


@trf.guard(a=trf.Int)
def foo(*, a=1):
    pass


foo()

# GuardError: {'a': DataError('is required')}

problem related to defaults property from FullArgSpec class

def foo(*, a=1): pass
def bar(a=1): pass

getargspec(foo)
# FullArgSpec(args=[], varargs=None, varkw=None, defaults=None, kwonlyargs=['a'], kwonlydefaults={'a': 1}, annotations={})

getargspec(bar)
# FullArgSpec(args=['a'], varargs=None, varkw=None, defaults=(1,), kwonlyargs=[], kwonlydefaults=None, annotations={})

https://github.com/Deepwalker/trafaret/blob/master/trafaret/base.py#L1493-L1496

here we need try to use the kwonlydefaults mapping

@Deepwalker
Copy link
Owner

committed some code, will make a release soon

@Deepwalker
Copy link
Owner

pls check 2.1.1
btw if you like this project, maybe we can convert into org etc.

@Arfey
Copy link
Collaborator Author

Arfey commented Apr 1, 2022

committed some code, will make a release soon

thx, i will check

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

No branches or pull requests

2 participants