I'm working on a project where I have a class with some 10ish decorators on it, where I'm using them to provide validation on some methods and attributes (if it's relevant, the validation is very general, and re-used elsewhere on other classes). I've been advised by a friend who is a lot more of a PEP8 stickler than I am that this is bad form---however, I cannot find a cite for that, or even good advice on what constitutes a good use of a decorator versus a bad or non-essential one.
My own introduction to using decorators came from Flask, where they provide routing information, and can be stacked a couple deep. Could someone provide cited information on proper versus improper decorator usage, and better alternatives?
What matters in Python is code readability. 10 or so decorators might be pretty hard to keep track of, while 2 o 3 are easier to read. You don't need a convention for every character you type: sometimes, you just have to go for what is easier to read
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