5 ms·
It's kind of cool that this is possible but I'm not adding that kind of complexity to my code unless I really need to. And I really never need to.
by jstx1 4y ago
It's kind of cool that this is possible but I'm not adding that kind of complexity to my code unless I really need to. And I really never need to.
- z3c0 4y agoDecorators 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 :^)
- Abishek_Muthian 4y agoHave felt the same way till I used one for fastapi , One can literally implement production grade* Machine Learning pipeline in 15 lines of code using transformers in a single python file; from fastapi import FastAPI from pydantic import BaseModel, constr, conlist from typing import List from transformers import pipeline classifier = pipeline("zero-shot-classification", model="models/distilbert-base-uncased-mnli") app = FastAPI() class UserRequestIn(BaseModel): text: constr(min_length=1) labels: conlist(str, min_items=1) class ScoredLabelsOut(BaseModel): labels: List[str] scores: List[float] @app.post("/classification", response_model=ScoredLabelsOut) def read_classification(user_request_in: UserRequestIn): return classifier(user_request_in.text, user_request_in.labels) *: Production grade if used in combination with workers, A python quirk I felt is not relevant to the topic of decorators.