mirage-ai-com / python-mirage-api

🐍 Mirage API Python Wrapper
https://pypi.python.org/pypi/mirage-api
MIT License
1 stars 0 forks source link

Default Value for a Dictionary should be None #1

Closed omarmhaimdat closed 11 months ago

omarmhaimdat commented 12 months ago

As dictionaries are passed by reference, this might lead to unexpected behavior

https://github.com/mirage-ai-com/python-mirage-api/blob/3520cc87a91ac36d06e666ebe260d3add974f6dc/mirage_api/__init__.py#L50C52-L50C52

valeriansaliou commented 11 months ago

Thank you for this feedback. Could you please elaborate?

omarmhaimdat commented 11 months ago

The simplest explanation can be found here: https://docs.quantifiedcode.com/python-anti-patterns/correctness/mutable_default_value_as_argument.html

TLDR:

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.

valeriansaliou commented 11 months ago

I understand the issue, however it doesnt seem to apply there, as we do not mutate the data nor the query objects contents by reference. We only re-assign a new local data variable, but that doesn't alter the original default object.