python3-krakenex
python3-krakenex copied to clipboard
Why set default value of dictionary parameters to None, but then change them to {} at beginning of method?
In several API methods like krakenex.api._query, why do you set the default value of some dictionary parameters to None, but then at the beginning of the method, immediately change None to the empty dictionary {}? Why not instead set the parameter default values to {}?
For example, why not replace
def _query(self, urlpath, data, headers=None, timeout=None):
if data is None:
data = {}
if headers is None:
headers = {}
with
def _query(self, urlpath, data={}, headers={}, timeout=None):
?
Looks like an atavism, judging by commits 839b9a1e and 11ac129a...
i think the suggested alternative -> def _query(self, urlpath, data={}, headers={}, timeout=None): would be problematic
By doing this, the headers and data objects are created at the time of defining the function. All function calls will then share the same object. I think the code is good as is and the issue can be closed, unless there is something i am missing
By doing this, the headers and data objects are created at the time of defining the function. All function calls will then share the same object. I think the code is good as is and the issue can be closed, unless there is something i am missing
I agree. At the time I opened this issue, I wasn't aware of this unfortunate Python behaviour. I can see how it could be a source of confusion for programmers new to Python.