What is your strategy to avoid dynamic typing errors in Python (NoneType has not attribute x)?
Posted
by Koen Bok
on Stack Overflow
See other posts from Stack Overflow
or by Koen Bok
Published on 2010-03-23T20:40:59Z
Indexed on
2010/03/23
20:43 UTC
Read the original article
Hit count: 377
python
|best-practices
Python is one of my favorite languages, but I really have a love/hate relationship with it's dynamicness. Apart from the advantages, it often results in me forgetting to check a type, trying to call an attribute and getting the NoneType (or any other) has no attribute x error. A lot of them are pretty harmless but if not handled correctly they can bring down your entire app/process/etc. Over time I got better predicting where these could pop up and adding explicit type checking, but because I'm only human I miss one occasionally and then some end-user finds it.
So I'm interested in your strategy to avoid these. Do you use type-checking decorators? Maybe special object wrappers? Please share...
© Stack Overflow or respective owner