[issue44216] Bug in class method with optional parameter

2021-05-23 Thread Steven D'Aprano
Steven D'Aprano added the comment: This is not a bug, this is working as the language is designed, and the behaviour occurs for all functions, not just class methods. Default values are only evaluated once, when the function is defined, not every time the function is called. This is even de

[issue44216] Bug in class method with optional parameter

2021-05-23 Thread William Pickard
William Pickard added the comment: This is not a bug but a side-affect at how defaulted parameters are stored. The rule of thumb is to never use mutable values as default values for parameters. When a method is created in the Python runtime, it checks if the signature has defaulted keyword a

[issue44216] Bug in class method with optional parameter

2021-05-23 Thread Ashish Shevale
New submission from Ashish Shevale : Consider the following piece of code class MyClass: def do_something(self, a, b = []): b.append(a) print("b contains", b) def caller(self): a = (1,2) self.do_something(a) a = MyClass().caller() a = MyClass().caller()