re: Beware of Python dict.get() VIEW POST

FULL DISCUSSION
 

That's pretty horrifying.
What's the robust solution here? Using a validation lib that will verify the whole data against a schema, and then have type annotations for the validated object?

 

Checking the return value properly. Or, just going for it and catching exceptions:

try:
    price_from_extruct = data_from_extruct['offer']['amount']
except:
    price_from_extruct = 0  # If you really wanted to do this.

The thing is, I find exceptions a good way of handling complex and arbitrary error flows. If you don't have a good story for what to do, trying to avoid the exceptions is just causing more headaches later.

code of conduct - report abuse