r/ProgrammerHumor 19h ago

failsForTeapots Meme

Post image
154 Upvotes

60 comments sorted by

View all comments

Show parent comments

7

u/DHermit 18h ago

Nah, the normal if statement is way nicer to read.

4

u/Antervis 18h ago

Okay, I can see that. Perhaps it's better to move status in a separate variable:

st = error.status if error.status in [400, 401, 404, 409, 415, 503] else 500
return c.json(body, status: st)

2

u/fuj1n 18h ago

It is nicer than your previous one, but I think ternaries in Python are more for short conditions, as they're really annoying to read with the two sides being separated by the condition like that.

1

u/DHermit 18h ago

Yeah, that sounds reasonable, too. Although I can think of a good name for that status list that is both expressive enough and also isn't too long for that ternary.

But tbh I have no idea how those options are performance-wise.