3 ms·
Have you thought about: message = "Shipment seems fine" if not_shipment_qty: message = "Shipment is not fine" elif shipment_qty < 0:
by zo1 11y ago
Have you thought about:
message = "Shipment seems fine"
if not_shipment_qty:
message = "Shipment is not fine"
elif shipment_qty < 0:
message = "No quantity"
abort(400, message)
- pyre 11y agoThat is semantically different. It always calls abort(). In this case abort() raises an exception that returns a HTTP 400. I'm not going to abort if everything seems fine. :P If you wanted to do this pattern, it would look more like this: message = None if not_shipment_qty: message = "Shipment is not fine" elif shipment_qty < 0: message = "No quantity" if message: abort(400, message=message) (Note: In this case the keyword argument form of message is required, because all keyword args get packaged up into a JSON body of the response.)