Skip to content

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

@Arfey

Description

@Arfey
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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions