5,002
questions
0
votes
0
answers
25
views
Trouble Using Decorators in Vite Typescript SWC
I created a vite typescript swc project, and I am having trouble getting decorators to work. I added this in tsconfig.app.json:
{
"compilerOptions": {
...
"...
-1
votes
0
answers
56
views
C# Promote object to new derived type without ICloneable
A library I'm using returns some object. I need some data from this object and pass it on, but I also need to add some more properties.
My though was to subclass it and add some properties. The ...
3
votes
1
answer
134
views
Python decorator class, with and without args, decorating class methods, and passes type checking
I want a Python decorator that:
Is a class
Can be used with or without args
Passes type checking with mypy
Can decorate class functions
I've found answers here that answer most combinations of these,...
0
votes
0
answers
34
views
Convert a schema (@sinclair/typebox) that is in a decorator to type
I'm currently working on a Fastify overlay that I'd like to make, the goal is to develop decorators to create routes quickly. I know fastify-decorators exists, I've been working with it for a long ...
0
votes
0
answers
41
views
CDI decorators support in Spring Boot
I am trying to use CDI decorators in Spring Boot application.
Here is the CDI Decorators for Spring beans article, that describes the purpose and the way how it could be done. The article is pretty ...
0
votes
0
answers
20
views
onQueueAdded event in nestjs for bull mq
I want to perform some action when a job is added into the queue. I have studied nestjs documentation for queues but didn't find any event decorator that handles add events (something like ...
0
votes
0
answers
34
views
Decorate Pydantic BaseModel with dynamic field_serializer
I want to add field_serializers from Pydantic to all models using decorators applied to the classes. However I get the 'Circullar reference detected' error.
from typing import List, Union, Callable, ...
0
votes
1
answer
66
views
tensorflow tf.function decorator and convergence
I am using a fully connected Neural Network as a function approximator in a more complex model. When I set up the model using the functional API I get convergence to a proper solution and the neural ...
1
vote
2
answers
101
views
role_required decorator for FastAPI route
Disclaimer and sorry words.. It's been quite a long time since I do not ask questions here and also I am a complete novice in FastAPI, so.. please do not judge too strong
I am playing with FastAPI ...
0
votes
0
answers
20
views
MediatR+Autofac NotificationHandler decorator pattern strange behaviour
I'm having a very strange issue with decorator pattern using MediatR (12.4.0) and Autofac (8.0.0) but I really cannot understand wether the problem is concerning Autofac, MediatR or (more probably) my ...
0
votes
0
answers
23
views
method decorator's originalMethod.apply un-defines parameters? [duplicate]
I have found similar questions, but most of them seem to focus on this and usually not purely typescript. However, I have a MINIMAL RUNNABLE EXAMPLE , that I just can't find an answer to.
I'm not ...
0
votes
1
answer
37
views
Typescript Decorator: how to get type of a property
I try to simplify my flow of handling data from Strapi, converting it using interfaces and converting back to Strapi format using three different mapping functions. For people who don't know Strapi, I ...
0
votes
0
answers
15
views
modify global variable in a decorated function [duplicate]
I have a decorator which inits a global dict which I want to modify within the decorated function. I have tried an implementation something like below:
def decorator():
def inner_function(func):
...
0
votes
0
answers
30
views
why does the inner_text_function is not defined when using decorators?
I dont understand why i cant access the name of the inner function decorated with the outer function?
it raise this error:
NameError: name 'inner_text_function' is not defined
def ...
0
votes
0
answers
37
views
Executing decorator without invoking the method
I am trying to register methods and functions into express. For example:
@Controller("/api/users/")
export class UserController {
constructor() {
console.log("constructor&...
1
vote
0
answers
30
views
Dynamic Response Handling for Multi-Tenant APIs
I am developing logic to handle REST API responses for different tenants (e.g., tenants A, B, and C) using a unified API approach. Each tenant has a specific response format based on a general ...
0
votes
0
answers
10
views
Set sanity decorators depending on the type
Is there any way to conditionally set decorators depending on the current type?
Something like this isProject:
export default {
name: 'textContent',
title: 'Text Content',
type: 'array',
...
2
votes
1
answer
51
views
Confusion about Caching with Decorators in Python
I'm working with Python decorators to implement caching for functions. I understand the basic concept of caching results to improve performance, but I'm struggling with how to handle different ...
0
votes
1
answer
56
views
Rails Internationalization – Lazy Lookup with a Presenter class
4.1.4 of the Rails Guide explains "Lazy" Lookup for the Internationalization gem.
As an example:
en.yml
en:
clients:
show:
good_client: 5 Star Client
app/views clients/show....
0
votes
0
answers
10
views
How to prevent multiple nested calls of a python decorator
Hi All the following is my code:
from functools import wraps
def log_return(level='DEBUG', label='Returned'):
"""
Decorator for logging the return of a function
level (...
0
votes
0
answers
31
views
Is it possible to actually change a function signature at runtime? (and have it enforced)
I want to dynamically change a function's signature. Here's my code:
from inspect import getfullargspec, signature
from functools import wraps
def mock(sign):
def deco(func):
@wraps(func)
...
1
vote
1
answer
36
views
Multikind Object validation in Nestjs DTO
I have code something like below. But I found out that @ValidateNested doesn't support when we do "TwoWheel | FourWheel" like this. Also I have no way of determining if incoming payload ...
0
votes
1
answer
37
views
Hide injected parameter by a decorator from function parameter hinting in PyCharm
I have a function that has a parameter injected by a decorator like so:
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
return func('hello', *args, **kwargs)
return ...
0
votes
1
answer
53
views
A custom decorator don't work with discord.py commands
I'm currently working on my bot in discord.py 2.0. Every time I create a new team, I need to check if the user is registered in the bot. If not, then send a request to register. Previously, I had to ...
2
votes
1
answer
51
views
Time library returns incorrect execution time for decorator functions in Flask
Say I have the following python files in my src directory for my Flask application (Flask-smortest to be specific):
src/
ham.py
eggs.py
endpoint.py
ham.py has 1 decorator function, while ...
0
votes
1
answer
51
views
Python decorator for class methods does not accept arguments from class attributes
I have a conditional decorator that executes action if 'True' is passed, it works great on standalone functions, but when trying to use it on class methods, I cannot pass an argument from class ...
0
votes
1
answer
126
views
How to Automatically Add and Update a createdBy Attribute in Every Entity Using NestJS and TypeORM
I'm developing a NestJS application and using TypeORM for database interactions. Each entity in my application already has createdAt and updatedAt attributes, which are automatically managed by ...
0
votes
3
answers
49
views
Why both of the custom decorators are called even if I only called one of them?
This is my custom decorator class. When I decorate them for functions and classes, auxiliary info is printed if these items are used.
# decorator.py
class BaseDecorator(object):
"""
...
1
vote
0
answers
44
views
Calling a Flask macro dynamically using a variable name
I have a big if-elif structure that calls specific macros based on the names of dynamically called variables, like this:
{% macro select_macro() %}
do stuff
{%- if context.key == 'value1' %}
{{ ...
0
votes
0
answers
26
views
Monitor request and response generated by any generic library
I am trying to build a generic benchmarking solution for LLMs, where I measure latency, number of tokens, and status code of API calls to the LLM.
Since most libraries used to build LLM-based ...
1
vote
0
answers
121
views
Decorators not work after update to Angular 17
After upgrade from Angular 15 to Angular 17 have not working property decorators in angular libs. I read about decorators ts 5 and i understood that decorator property can't change value. But how call ...
0
votes
2
answers
44
views
request data not able to access with this code in wrapper function how can i python3 django decorator
not able to access request data in deorator how can i do this ? in my wrapper function
def my_decorator(view_func):
def wrapper(request, *args, **kwargs):
print('-start-')
print(...
2
votes
1
answer
66
views
How to decorate instance methods and avoid sharing closure environment between instances
I'm having trouble finding a solution to this problem. Whenever we decorate a method of a class, the method is not yet bound to any instance, so say we have:
from functools import wraps
def decorator(...
0
votes
1
answer
59
views
Defining specific class functionality using decorators as information about class overrides
I have implemented a TypeScript class Decorator function which allows me to decorate classes of the same kind. If Decorator is present above some class, that class should look into Decorator stored ...
0
votes
0
answers
53
views
How to use this in nestjs decorator
I want to set the file limit on upload using
new MaxFileSizeValidator({ maxSize: this.configService.get<number>('uploadLimit') }),
and I receive configService on controller
constructor(...
0
votes
0
answers
22
views
How to implement python's decorators so that it doesn't execute on recursive calls? [duplicate]
I'm actually trying to implement some decorators in Python to test the performances of my programm, but on recursive fonctions it keeps calling the decorator and produce something unreadable.
Here is ...
0
votes
1
answer
79
views
I have a problem with parametrs decorator
I want to use TSyringe to implement DI in my application. So, i use interfases, thats why i have to apply a parametrs decorator to link the interface and the class. But i have a problem "...
3
votes
2
answers
94
views
In python, how can/should decorators be used to implement function polymorphism?
Supposing we have a class as follows:
class PersonalChef():
def cook():
print("cooking something...")
And we want what it cooks to be a function of the time of day, we could do ...
1
vote
1
answer
53
views
How to override the internal read query of class or method in django
I wan't to override the internal read query present inside my class or method. I wan't to write generalised solution so that it should work on the class or method where I wan't to modify the read ...
1
vote
1
answer
54
views
unexpected behavior with `inspect.getmembers` on @property methods that throw exceptions
I feel like I'm encountering a rather strange behavior in Python. Try it out yourself:
import inspect
class SomeClass:
def __init__(self):
inspect.getmembers(self, predicate=inspect....
1
vote
1
answer
41
views
How to use with on a protected member extension in Kotlin?
I stumbled upon this when trying to create a custom androidx.compose.ui.graphics.painter.Painter for my jetpack compose application. I'd like to create a decorator like:
class MyPainter(private val ...
0
votes
0
answers
21
views
Python Sphinx autodoc and class decorator [duplicate]
I try to use sphinx to automatically generate documentation. My rst file looks like this:
.. automodule:: function
:members:
:undoc-members:
:show-inheritance:
This works fine, except ...
0
votes
1
answer
79
views
Custom param decorator is only for controller in nestjs?
Is the custom param decorator in nestjs is only for the controller?
I am trying to apply it on the param of the function of a class, but when m calling that function it says expected 1 argument, which ...
0
votes
0
answers
35
views
Getting descriptor value as undefined when using Accessor Decorators
class Point {
private _x: number;
constructor(x: number, y: number) {
this._x = x;
}
@configurable(false)
get x() {
return this._x;
}
}
function configurable(value: boolean) {
...
2
votes
0
answers
261
views
native decorators in typescript + nextjs
In the writing of mobx I notice the following error:
./src/app/stores/resource_store.ts
Error:
× Unexpected token `@`. Expected identifier, string literal, numeric literal or [ for the computed key
...
1
vote
1
answer
62
views
How to use class decorator pattern if an original class method is recursive in TypeScript?
Just to clarify, I'm using decorator pattern/approach from https://refactoring.guru/design-patterns/decorator and not experimental decorators feature in TypeScript.
I'm trying to extend the next ...
0
votes
0
answers
193
views
'coroutine' object is not callable
I tried to check the user's permissions through the decorator, but an error was thrown
async def perm_check(func):
async def wrapper(*args, **kwargs):
update: telegram.Update = kwargs.get(&...
1
vote
3
answers
82
views
*Dynamically* decorate a recursive function in Python
I have a scenario where I need to dynamically decorate recursive calls within a function in Python. The key requirement is to achieve this dynamically without modifying the function in the current ...
0
votes
0
answers
306
views
Decorators in Drizzle ORM schema files
I am new to drizzle ORM and I am building a node application with type-graphql. I have to define a drizzle schema and a graphql schema. I would like to define both schemas in the same file, so I can ...
1
vote
1
answer
174
views
How to assign value to a decorated property in parent class constructor?
I have a User class that has a decorated property "name". I am trying to initialize this property in parent class (Base) constructor using Object.assign but the value is "undefined"...