Re:Beyond PEP 8 – Best practices for beautiful intelligible ...
by zo1 on Saturday August 08, 2015 @03:00AM
(#10026583)
Have you thought about:
[ Parent
| on HN ]
Re:Beyond PEP 8 – Best practices for beautiful intelligible ...
by pyre on Saturday August 08, 2015 @10:12AM
(#10027276)
That 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.)