Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions refex/python/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,7 @@ def _coerce_list(values):
_IS_SUBMATCHER_LIST_ATTRIB = __name__ + '._IS_SUBMATCHER_LIST_ATTRIB'


def submatcher_attrib(
*args,
**kwargs: Any): # TODO: make walk a kwarg when Py2 support is dropped.
def submatcher_attrib(*args, walk: bool = True, **kwargs: Any):
"""Creates an attr.ib that is marked as a submatcher.

This will cause the matcher to be automatically walked as part of the
Expand All @@ -199,15 +197,13 @@ def submatcher_attrib(
Returns:
An attr.ib()
"""
if kwargs.pop('walk', True):
if walk:
kwargs.setdefault('metadata', {})[_IS_SUBMATCHER_ATTRIB] = True
kwargs.setdefault('converter', coerce)
return attr.ib(*args, **kwargs)


def submatcher_list_attrib(
*args,
**kwargs: Any): # TODO: make walk a kwarg when Py2 support is dropped.
def submatcher_list_attrib(*args, walk: bool = True, **kwargs: Any):
"""Creates an attr.ib that is marked as an iterable of submatchers.

This will cause the matcher to be automatically walked as part of the
Expand All @@ -222,7 +218,7 @@ def submatcher_list_attrib(
Returns:
An attr.ib()
"""
if kwargs.pop('walk', True):
if walk:
kwargs.setdefault('metadata', {})[_IS_SUBMATCHER_LIST_ATTRIB] = True
kwargs.setdefault('converter', _coerce_list)
return attr.ib(*args, **kwargs)
Expand Down