Re: Optional arguments in a class behave like class attributes.

2022-10-17 Thread Antoon Pardon
You can use the following decorator for what you probably want. def copy_defaults(func): """ This decorator makes that defaults values are copied on a call. """ signature = inspect.signature(func) parameter_items = list(signature.parameters.items()) @wraps(func) def

Re: Optional arguments in a class behave like class attributes.

2022-10-17 Thread Chris Angelico
On Tue, 18 Oct 2022 at 01:39, Abderrahim Adrabi wrote: > So, these default values behave like class attributes, here is a demo: > > # Using a list - > class GameOne: > def __init__(self, games = []) -> None: > self.games = games > This makes the default be a sing

Optional arguments in a class behave like class attributes.

2022-10-17 Thread Abderrahim Adrabi
Hi all, I tried to create a class with some optional arguments as always, but this time I used the default values to be lists, dictionaries, and object references. So, these default values behave like class attributes, here is a demo: # Using a list - class GameOne: