capless / warrant

Python library for using AWS Cognito. With support for SRP.
Apache License 2.0
468 stars 192 forks source link

Anti-pattern - Use of default mutable arguments dict(), {} and [] #32

Closed nueverest closed 7 years ago

nueverest commented 7 years ago

Passing mutable lists or dictionaries as default arguments to a function can have unforeseen consequences. Usually when a programmer uses a list or dictionary as the default argument to a function, the programmer wants the program to create a new list or dictionary every time that the function is called. However, this is not what Python does. The first time that the function is called, Python creates a persistent object for the list or dictionary. Every subsequent time the function is called, Python uses that same persistent object that was created from the first call to the function.

Reference: https://docs.quantifiedcode.com/python-anti-patterns/correctness/mutable_default_value_as_argument.html

armicron commented 7 years ago

This issue should be closed.