I'm using pylint on my code and getting the error
R1710: Either all return statements in a function should return an expression, or none of them should. (inconsistent-return-statements)
There are only two possible return statements and they both return expression if I am not mistaken
@api_view(["GET", "POST"])
def user_info(request):
if request.method == 'GET':
username = request.GET.get("username")
password = request.GET.get("password")
return JsonResponse(error_handle(serialize(username, password)))
if request.method == 'POST':
username = request.data["username"]
password = request.data["password"]
return JsonResponse(error_handle(serialize(username, password)))
def error_handle(serializer):
error = serializer["error"].value
if error > 0:
return {"success": "false", "internal_code": error}
return {"success": "true",
"account_token": serializer.data["account_token"],
"user_id": serializer.data["id"],
"account_name": serializer.data["account_name"],
"account_permission": serializer.data["account_permission"],
"pin": serializer.data["pin"]
}
def serialize(user, password):
data = Account.objects.get(username=user, password=password)
return AccountSerializer(data)