I am testing some code I have written, and when functioning normally, it could raise a TypeError of the variety where 'NoneType' object is not iterable. Since this expected, I would like to deal with this as it happens, without inadvertently hiding other TypeErrors.
How can I test if my TypeError is for 'NoneType', and not for other reasons? I have looked at the attributes of the TypeError but can't seem to understand which would tell me the cause for the error.
You're essentially trying to check for None types since the error you're receiving indicates directly that you're trying to iterate over some variable that is None. I'd use the classic python check for None to determine when that is the case:
if my_iterable_collection is None:
... no good
else:
... we're good
This is how I'd try and find and bubble up None related issues, rather than using try/catch. You'll know the exact error is related to None with a high degree of granularity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With