jmespath / jmespath/jmespath.py

Unexpected mutations when using list or object literals in expressions

Open
#318 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
2.4k
Forks
212
PR merge metrics
No merged PRs in 30d

Description

Example code:

```python
import jmespath

data = {}
my_list = jmespath.search('`[]`', data)
my_list.extend([1, 2, 3])
print(my_list)

new_data = {}
new_list = jmespath.search('`[]`', new_data)
new_list.extend([9, 8, 7])
print(new_list)
```

Expected Output:
```
[1, 2, 3]
[9, 8, 7]
```

Actual Output:
```
[1, 2, 3]
[1, 2, 3, 9, 8, 7]
```

The expression is getting cached as well as a reference to the empty list literal. This is causing unexpected mutations to other lists that should not be getting mutated.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.