We have a function that processes the user request if it is not None, how best to style it? I did not find a better choice in PEP8
Style 1
def user_handler(user):
if db.getUser(user) is not None:
"""
Here we have a big body of function
"""
return {'message': 'Successful handled'}
else:
return {'message': 'User not found'}
Style 2
def user_handler(user):
if db.getUser(user) is None:
return {'message': 'User not found'}
"""
Here we have a big body of function
"""
return {'message': 'Successful handled'}
UPD 1: Since there were a lot of questions in the comments regarding the content of the code, I remade the question into a more real one.
None
as the request in the first place? The whole premise of this question is a code smell. – 200_success Mar 26 '22 at 23:31return False
) are close together. In Style 1, Pylint will also flag the unnecessaryelse
, since both branchesreturn
. – amon Mar 26 '22 at 23:34