You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Mutable default arguments are recreated on each function call instead of shared between calls #909
Mutable default arguments appear to behave differently in Transcrypt compared with CPython.
In Python, default argument expressions are evaluated when the function definition is executed. Therefore, when a mutable object such as [] is used as a default argument, calls that omit the argument use the same object.
In Transcrypt 3.9.5, the default list appears to be recreated for every function call instead.
Output when running the Transcrypt-generated JavaScript
[1] [2]
False
Expected behaviour
The default value of lst should be created once when the function is defined. Therefore, calls to append_list2() without explicitly supplying lst should receive the same list object, and lst1 is lst2 should be True.
Generated JavaScript
The generated JavaScript appears to initialise the default argument inside the function when the argument is omitted, conceptually equivalent to:
Activity