decorator Questions
1
Solved
I have a workflow that is pretty picky with the PSCustomObjects it receives. I often use Select-Object to get the properties from the objects I want to keep and sometimes I need to convert some of ...
Geode asked 21/9 at 11:8
5
Solved
I want to write a decorator that acts differently depending on whether it is applied to a function or to a method.
def some_decorator(func):
if the_magic_happens_here(func): # <---- Point of i...
3
Solved
When I try to use staff_view, I get redirected in the admin authentication interface.
from django.contrib.admin.views.decorators import staff_member_required
@staff_member_required
def staff_v...
Bergeron asked 2/8, 2012 at 9:28
3
I've developed my own, but it seems like it's a great enough thing that someone else probably thought of it first and did a better job ;)
The goal is to be able to write, in your myapp/views.py
r...
Ambitendency asked 15/1, 2013 at 17:37
3
Solved
I am writing unit tests for an MCU that communicates commands through the USB port and checks their response.
If one unit test fails it makes sense for me to do some debugging in the MCU.
Therefore...
Catalano asked 8/5, 2015 at 10:3
5
I'm trying to write a "staff only" decorator for Django, but I can't seem to get it to work:
def staff_only(error='Only staff may view this page.'):
def _dec(view_func):
def _view(request, *args...
5
Solved
In python code I often see the use of @property.
If I understand correctly, with the property function a getter setter and deleter can be defined.
Why would one use @property if the setter and d...
Metastasis asked 8/6, 2011 at 6:46
4
Is it possible to decorate a function based on a condition?
a'la:
if she.weight() == duck.weight():
@burn
def witch():
pass
I'm just wondering if logic could be used (when witch is called?) ...
Rabbi asked 22/9, 2010 at 20:55
10
Solved
I am trying to figure out how to get the names of all decorators on a method. I can already get the method name and docstring, but cannot figure out how to get a list of decorators.
Schmeltzer asked 12/7, 2010 at 20:30
6
Solved
I have been trying to create a decorator that can be used with both functions and methods in python. This on it's own is not that hard, but when creating a decorator that takes arguments, it seems ...
3
Solved
I have a decorator
def deco(func):
def inner(params):
#< DO STUFF WITH func >
return inner
And a base class
class GenericClass:
def __init__(self,value):
self.value = value
def meth...
13
Solved
I have a function with a decorator that I'm trying test with the help of the Python Mock library. I'd like to use mock.patch to replace the real decorator with a mock 'bypass' decorator which just ...
Birkenhead asked 5/10, 2011 at 20:50
3
Solved
I have a custom method decorator like this.
export function CustomDecorator() {
return applyDecorators(
UseGuards(JwtAuthGuard)
);
}
Inside the Custom Decorator, I want to get the Request Head...
6
Solved
I want to create a decorator that profiles a method and logs the result. How can this be done?
8
Solved
When I attempt to use a static method from within the body of the class, and define the static method using the built-in staticmethod function as a decorator, like this:
class Klass(object):
@sta...
Zobias asked 3/10, 2012 at 23:12
3
Solved
Is there a way to set the execution order of decorators when describing a DTO class in NestJS using class-validator and class-transformer packages ?
Following code fails when the value of foo is se...
Yakka asked 7/9, 2021 at 8:39
42
Solved
This question is not for the discussion of whether or not the singleton design pattern is desirable, is an anti-pattern, or for any religious wars, but to discuss how this pattern is best implement...
Pap asked 20/7, 2011 at 10:47
4
Solved
I want to achieve something like this using nest.js:
(something very similar with Spring framework)
@Controller('/test')
class TestController {
@Get()
get(@Principal() principal: Principal) {
...
Ieyasu asked 7/4, 2019 at 15:50
5
Solved
As I've understood it there are two ways to do a Python decorator, to either use the __call__ of a class or to define and call a function as the decorator. What's the advantages/disadvantages of th...
Weatherproof asked 24/4, 2012 at 8:2
10
Solved
I am trying to write a currying decorator in python. I got this far:
def curry(fun):
cache = []
numargs = fun.func_code.co_argcount
def new_fun(*args, **kwargs):
print(args)
print(kwargs)
...
4
I've been struggling to find examples of how to write a custom attribute to validate method parameters, i.e., turn this form:
public void DoSomething(Client client)
{
if (client.HasAction("do_som...
Harpist asked 17/6, 2013 at 14:44
8
Solved
I just came across two patterns.
Strategy Pattern
Decorator
Strategy Pattern :-
Strategy pattern gives several algorithms that can be used to perform
particular operation or task.
Dec...
Ebonize asked 17/10, 2014 at 10:19
9
Solved
My problem, and why
I'm trying to write a decorator for a method, @cachedproperty. I want it to behave so that when the method is first called, the method is replaced with its return value. I also ...
Dittany asked 18/4, 2016 at 1:55
5
Solved
I wanted to dynamically set the Websockets-gateway port from config in NestJS. Below is my websockets-gateway code.
import { WebSocketGateway } from '@nestjs/websockets';
const WS_PORT = parseInt(...
Vesicate asked 4/10, 2021 at 11:49
2
from pydantic import BaseModel
class Request(BaseModel):
num: int
@validator("num")
@classmethod
def validate_num(cls, num: int) -> int:
return num
PyCharm gives the warning &...
1 Next >
© 2022 - 2024 — McMap. All rights reserved.