4 ms·
Decorators are one of those language features that I want to use more of, but every time I attempt to, I realize that what I'm doing could be achieved more easi
by z3c0 4y ago
Decorators are one of those language features that I want to use more of, but every time I attempt to, I realize that what I'm doing could be achieved more easily another way.
- zmgsabst 4y agoI use two with any regularity: 1. @dataclass https://docs.python.org/3/library/dataclasses.html https://docs.python.org/3/library/dataclasses.html 2. @cuda.jit https://numba.pydata.org/numba-doc/latest/cuda/kernels.html https://numba.pydata.org/numba-doc/latest/cuda/kernels.html
- dharmab 4y agoAnother I use is tenacity, when I need to call unreliable external services: https://tenacity.readthedocs.io/en/latest/ https://tenacity.readthedocs.io/en/latest/
- monkeybutton 4y agoAside from @dataclass, @lru_cache is my most used.
- ConceptJunkie 4y agoI created a decorator for validating arguments for functions that are receiving arguments from user input. It eliminated _so much_ boilerplate code. I use decorators quite a bit. The feature is incredibly powerful. Once you find @lru_cache, you start realizing how many ways you can take advantage of the feature.
- pizza 4y ago@cached_property is the new lru_cache for me, much of the time :^)