Deepwalker / trafaret

Ultimate transformation library that supports validation, contexts and aiohttp.
http://trafaret.readthedocs.org/en/latest/
BSD 2-Clause "Simplified" License
177 stars 31 forks source link

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

Open Arfey opened 2 years ago

Arfey commented 2 years ago
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 commented 2 years ago

committed some code, will make a release soon

Deepwalker commented 2 years ago

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

Arfey commented 2 years ago

committed some code, will make a release soon

thx, i will check