I noticed a strange behavior while using the splat operator.
I ran the following code on different computers:
def func(m):
m(1)
return []
messages = []
print(
[*messages, *func(messages.append)]
)
Test 1
- PC: MacBook Air M1
- Python version: 3.9.7
- Output:
[]
Test 2
- PC: MacBook Pro Intel
- Python version: 3.8.9
- Output:
[1]
Test 3
- Google Colab
- Python version: 3.7.12
- Output:
[1]
Test 4
- Online interpreter: https://www.programiz.com/python-programming/online-compiler/
- Python version: unknown
- Output:
[1]
My first impression was that the splat was applied to messages
before m(1)
in Test 1, but after in the other tests. Since this doesn't seem to be associated to the Python version, I guess there's something different with the M1 chip...
I couldn't find a clear explanation of what should happen here: https://docs.python.org/3/reference/expressions.html#evaluation-order