Comment on Python Performance: Why 'if not list' is 2x Faster Than Using len()

<- View Parent
sugar_in_your_tea@sh.itjust.works ⁨2⁩ ⁨days⁩ ago

Sure. But is None invalid input in your case, whereas [] is valid? If so, make that check explicit, don’t rely on an implicit check that len(…) does.

When I see TypeError in the logs, I assume the developer screwed up. When I see ValueError in the logs, I assume the user screwed up. Ideally, TypeError should never happen, and every case where it could happen should transform it to another type of exception that indicates where the error actually lies.

The only exceptions I want to see in my code are:

Implicit ones like accessing attributes on None or calling methods that don’t exist shouldn’t be happening in production code.

source
Sort:hotnewtop