Skip to content

Commit

Permalink
Implicit chaining in lists: Make [x, y,...] same as [(x, y, ...)]
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrick committed Apr 27, 2021
1 parent 67cd5a4 commit 3f8893e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion glom/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1833,7 +1833,7 @@ def _handle_dict(target, spec, scope):


def _handle_list(target, spec, scope):
subspec = spec[0]
subspec = Pipe(*spec)
iterate = scope[TargetRegistry].get_handler('iterate', target, path=scope[Path])
try:
iterator = iterate(target)
Expand Down
8 changes: 8 additions & 0 deletions glom/test/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,14 @@ def test_pipe():
assert repr(Pipe(1, Pipe([2], dict))) == 'Pipe(1, Pipe([2], dict))'


def test_list_implicit_chaining():
target = [{'outer': {'inner': str(i ** 2)}} for i in range(5)]
spec_implicit = ['outer', 'inner', int]
spec_explicit = [('outer', 'inner', int)]

assert glom(target, spec_implicit) == glom(target, spec_explicit) == [0, 1, 4, 9, 16]


_IS_PYPY = '__pypy__' in sys.builtin_module_names
@pytest.mark.skipif(_IS_PYPY, reason='pypy othertype.__repr__ is never object.__repr__')
def test_api_repr():
Expand Down

0 comments on commit 3f8893e

Please sign in to comment.