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
test.py: This code snippet trigger this incorrect behavior.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2021-01-10.14:58:42.480>created_at=<Date2021-01-10.14:43:44.558>labels= ['type-bug', 'invalid', '3.9']
title='__init__ function may incur an incorrect behavior if passing a list as a parameter and set its default value as empty'updated_at=<Date2021-01-10.15:00:28.855>user='https://github.com/haoyang9804'
It seems that when I pass a list "b" to __init__ function with default value empty list. Every time I create a new instance of this class and append one new variable to "self.a", the default value of "b" changed at the next time I create another instance of class A.
The outcome of this code snippet is
a = []
[1]
a = [1]
[1, 1]
a = [1, 1]
[1, 1, 1]
I am new to python. Is it a legal behavior in python? If yes, what is the principle beneath it? Thanks in advance!
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: