Skip to content

Commit

Permalink
rename functions and args in comparable_itemgetter
Browse files Browse the repository at this point in the history
  • Loading branch information
arturponinski committed Feb 5, 2022
1 parent ae69b45 commit 770812f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions petl/comparison.py
Expand Up @@ -107,23 +107,23 @@ def comparable_itemgetter(*args):
getter = operator.itemgetter(*args)
getter_with_default = _itemgetter_with_default(*args)

def getter_with_fallback(x):
def _getter_with_fallback(obj):
try:
return getter(x)
return getter(obj)
except (IndexError, KeyError):
return getter_with_default(x)
g = lambda x: Comparable(getter_with_fallback(x))
return getter_with_default(obj)
g = lambda x: Comparable(_getter_with_fallback(x))
return g


def _itemgetter_with_default(*args):
""" itemgetter compatible with `operator.itemgetter` behavior, filling missing
values with default instead of raising IndexError or KeyError """
def get_default(obj, item, default):
def _get_default(obj, item, default):
try:
return obj[item]
except (IndexError, KeyError):
return default
if len(args) == 1:
return partial(get_default, item=args[0], default=None)
return lambda obj: tuple(get_default(obj, item=item, default=None) for item in args)
return partial(_get_default, item=args[0], default=None)
return lambda obj: tuple(_get_default(obj, item=item, default=None) for item in args)

0 comments on commit 770812f

Please sign in to comment.