Lambda may not be necessary
202 if recipient_data["receive_limit_reached"] and not force:
203 remaining_time = cooldown_period - (now - last_received)
204 hours, minutes, seconds = map(
205 lambda x: int(x),206 [
207 remaining_time.seconds // 3600,
208 remaining_time.seconds % 3600 // 60,
Description
A lambda that calls a function without modifying any of its parameters is unnecessary. Python functions are first-class objects and can be passed around in the same way as the resulting lambda. It is recommended to remove the lambda and use the function directly.
It is preferred to use the function hash
directly as the lambda function calls the same function without any modifications.
Another reason to avoid the lambda function here is that it makes debugging difficult.
Lambdas show as <lambda>
in tracebacks, where functions will display the function’s name.
Bad practice
items = [1, 2, 3]
hashify = lambda x: hash(x)
hashed_items = map(hashify, items)
Recommended
items = [1, 2, 3]
# pass the builtin `hash` instead of the wrapper `hashify`
hashed_items = map(hash, items)