The following prints {'a': 'a', 'b': 'b'}
:
def foo(a: str = "a", b: str = "b") -> None:
print(locals())
foo() # Prints {'a': 'a', 'b': 'b'}
Which I’d expect as locals
in Python 3.7+ returns the order of creation.
But the below prints {'b': 'b', 'a': 'a'}
def foo(a: str = "a", b: str = "b") -> None:
print(locals())
lambda: a
foo() # Prints {'b': 'b', 'a': 'a'}
It seems like it delayed the order of variable creation, which is strange. Why is this?