Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Implicit chaining in lists: Make [x, y,...] same as [(x, y, ...)] #221

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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