[issue46450] namedtuple leaks data between instances when field's default value is empty list

2022-01-21 Thread maximus733
maximus733 <3ed7qja...@liamekaens.com> added the comment: Thanks for the clarification. -- ___ Python tracker ___ ___ Python-bugs-li

[issue46450] namedtuple leaks data between instances when field's default value is empty list

2022-01-21 Thread Eric V. Smith
Eric V. Smith added the comment: Also see https://docs.python.org/3/faq/programming.html#why-are-default-values-shared-between-objects -- nosy: +eric.smith resolution: -> not a bug stage: -> resolved status: open -> closed ___ Python tracker

[issue46450] namedtuple leaks data between instances when field's default value is empty list

2022-01-20 Thread Dennis Sweeney
Dennis Sweeney added the comment: This seems to be the standard confusion people have with mutable defaults, just with namedtuple defaults rather than function defaults. Similar behavior elsewhere in Python: >>> def f(x, y=[]): ... y.append(x) ... print(y) ... ... >>> f(1) [1]

[issue46450] namedtuple leaks data between instances when field's default value is empty list

2022-01-20 Thread Curtis M
New submission from Curtis M <3ed7qja...@liamekaens.com>: Example code to replicate issue on python 3.10.2 is attached. How to replicate issue: 1. Define a namedtuple where all fields have default values. At least one field's default value will be an empty list: [] 2. Instantiate 2 instances o