Description
Several methods in esp/formsstack/api.py use mutable default arguments (args = {}).
Examples:
def delete(self, id, args = {}):
def create_field(self, form, args = {}):
def __request(self, method, args = {})
Using mutable objects like {} as default parameters in Python is unsafe because the same object instance is reused across function calls. If the dictionary is modified during one call, the modified state persists in subsequent calls, which can lead to unintended side effects and hard-to-trace bugs.
The recommended pattern is to use None as the default value and initialize the dictionary inside the function.
Steps to Reproduce
- Open the file
esp/formsstack/api.py.
- Locate the following methods:
- delete(self, id, args = {})
- create_field(self, form, args = {})
- __request(self, method, args = {})
- Observe that a mutable default argument (
{}) is used.
- If the dictionary is modified during a call, the same mutated object may be reused in later calls.
Expected Behavior
Functions should avoid mutable default arguments.
The safer pattern is:
def delete(self, id, args=None):
if args is None:
args = {}
This ensures a new dictionary is created for every function call.
Actual Behavior
The methods currently define args with a default value of {}, which causes Python to reuse the same dictionary instance between function calls.
This may lead to unexpected behavior if the dictionary is modified during execution.
Screenshots
No response
Operating System
No response
Browser
No response
Additional Context
No response
Description
Several methods in
esp/formsstack/api.pyuse mutable default arguments (args = {}).Examples:
def delete(self, id, args = {}):
def create_field(self, form, args = {}):
def __request(self, method, args = {})
Using mutable objects like
{}as default parameters in Python is unsafe because the same object instance is reused across function calls. If the dictionary is modified during one call, the modified state persists in subsequent calls, which can lead to unintended side effects and hard-to-trace bugs.The recommended pattern is to use
Noneas the default value and initialize the dictionary inside the function.Steps to Reproduce
esp/formsstack/api.py.{}) is used.Expected Behavior
Functions should avoid mutable default arguments.
The safer pattern is:
def delete(self, id, args=None):
if args is None:
args = {}
This ensures a new dictionary is created for every function call.
Actual Behavior
The methods currently define
argswith a default value of{}, which causes Python to reuse the same dictionary instance between function calls.This may lead to unexpected behavior if the dictionary is modified during execution.
Screenshots
No response
Operating System
No response
Browser
No response
Additional Context
No response