From 3f8893e1bdf73168d27689df1959b530be1ff930 Mon Sep 17 00:00:00 2001 From: Maciej Katafiasz Date: Mon, 26 Apr 2021 19:39:01 -0700 Subject: [PATCH] Implicit chaining in lists: Make [x, y,...] same as [(x, y, ...)] Fixes #220 --- glom/core.py | 2 +- glom/test/test_basic.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/glom/core.py b/glom/core.py index d2f9d69..16d5a10 100644 --- a/glom/core.py +++ b/glom/core.py @@ -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) diff --git a/glom/test/test_basic.py b/glom/test/test_basic.py index 2c561c5..65d4212 100644 --- a/glom/test/test_basic.py +++ b/glom/test/test_basic.py @@ -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():