From 5fe9076631b8c6c706e6421aeeb25aa5c53e850b Mon Sep 17 00:00:00 2001 From: Nathan Florea Date: Thu, 2 Jun 2016 16:04:39 -0700 Subject: [PATCH] Remove some mutable default arguments. These ones don't fix any bugs, because the mutable arg is never passed outside of the callable or mutated. But it's good practice to not use them in case those invariants are changed in the future. --- tools/lint-all | 6 +++--- zerver/lib/response.py | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tools/lint-all b/tools/lint-all index 9c29048dfc..a41ef6ab8c 100755 --- a/tools/lint-all +++ b/tools/lint-all @@ -86,13 +86,13 @@ def check_pyflakes(): failed = True return failed -def custom_check_file(fn, rules, skip_rules=[]): +def custom_check_file(fn, rules, skip_rules=None): failed = False lineFlag = False for i, line in enumerate(open(fn)): skip = False lineFlag = True - for rule in skip_rules: + for rule in skip_rules or []: if re.match(rule, line): skip = True if skip: @@ -183,7 +183,7 @@ python_rules = [ 'exclude': set(['tools/lint-all']), 'exclude_line': set([ # function definition - ('zerver/lib/response.py', 'def json_error(msg, data={}, status=400):'), + ('zerver/lib/response.py', 'def json_error(msg, data=None, status=400):'), # No need to worry about the following as the translation strings # are already captured ('zerver/middleware.py', diff --git a/zerver/lib/response.py b/zerver/lib/response.py index b9a10163ff..2ad5b03a19 100644 --- a/zerver/lib/response.py +++ b/zerver/lib/response.py @@ -23,16 +23,17 @@ def json_method_not_allowed(methods): "allowed_methods": methods}) return resp -def json_response(res_type="success", msg="", data={}, status=200): +def json_response(res_type="success", msg="", data=None, status=200): content = {"result": res_type, "msg": msg} - content.update(data) + if data is not None: + content.update(data) return HttpResponse(content=ujson.dumps(content) + "\n", content_type='application/json', status=status) -def json_success(data={}): +def json_success(data=None): return json_response(data=data) -def json_error(msg, data={}, status=400): +def json_error(msg, data=None, status=400): return json_response(res_type="error", msg=msg, data=data, status=status) def json_unhandled_exception():