Skip to main content
Filter by
Sorted by
Tagged with
1 vote
3 answers
110 views

I have a decorator in the root of a package that should log out information about unexpected exceptions. from logging import getLogger from os.path import basename from traceback import extract_tb ...
ludovico's user avatar
1 vote
0 answers
83 views

I am attempting to create a decorator which prints the current call chain into the terminal in a similar format to the windows tree command. An object of my class type is tied to each function as they ...
lily's user avatar
  • 11
0 votes
2 answers
112 views

I have a few methods that require a certain condition to be applied to function properly. To avoid code repetition I've created a decorator to check if this condition is applied and only then execute ...
good user's user avatar
3 votes
1 answer
230 views

I have been working with Timefold in Python for a while and wrote a setup manual for a Timefold project. When testing this setup manual on another device we ran into a problem. It doesn't seem to ...
Steven's user avatar
  • 41
2 votes
1 answer
60 views

There are two classes and I want to wrap item.foo method only once, to prevent cache = {param1: 'param_value'} being reinited class Foo: _count = 0 def foo(self, param2): self._count +...
Aleksandr Lekontsev's user avatar
3 votes
2 answers
182 views

I have hundreds of functions test1, test2, ... Function testX may or may not have kwargs: def test1(x, z=1, **kwargs): pass def test2(x, y=1): pass def test3(x, y=1, z=1): pass ... and I ...
lei zhang's user avatar
  • 203
0 votes
1 answer
182 views

I am trying to create a decorator which enables me to register callback functions to an instance of ClassB. I would like to use this decorator in other classes within my program (eg. ClassA) but want ...
bchiddy's user avatar
  • 11
1 vote
1 answer
58 views

when trying to start the server it cannot find the decorator from django.contrib.auth.decorators import login_required, user_passes_test, staff_member_required ... @staff_member_required def ...
Алексей Андреев's user avatar
0 votes
0 answers
68 views

I want to create a custom Collection (FnColl) that is specific for an ObjectType T and holds a list of Callables, each taking an object of type T and returning any value. class FnColl[T]: def ...
DblDpl's user avatar
  • 1
0 votes
1 answer
91 views

I'm working on a Python project where I'm using decorators to wrap functions and methods with some logic. However, I've encountered an issue where inspect identifies the decorated methods as functions ...
Niemand's user avatar
  • 25
0 votes
1 answer
178 views

I have a Python package with optional dependencies defined in pyproject.toml. I want to run pytest while ensuring that specific tests are executed only if the relevant optional dependencies are ...
Sam's user avatar
  • 1
0 votes
0 answers
38 views

I can profile and visualize my entire application with: python -m cProfile -o program.prof my_program.py snakeviz program.prof Is it possible to write a decorator that will profile only some ...
Ohumeronen's user avatar
  • 2,146
0 votes
2 answers
36 views

I have a Python class that needs to dynamically choose between two methods based on a condition. Both methods take parameters. I want to use a property to determine which method to call. How can I ...
Mikhail Goussarov's user avatar
0 votes
1 answer
310 views

(I am almost certain the wording of the question does not make sense, but I have yet to find a better one.) I have the following code that I want to type-check: from collections.abc import Callable ...
bers's user avatar
  • 6,299
0 votes
1 answer
172 views

I wrote my own session logic and use the following decorator to check the request: def require_session(func): @wraps(func) async def wrapper(*args, **kwargs): request = kwargs['request'...
kos1posha's user avatar
0 votes
2 answers
115 views

I want to combine multiple @statimethod decorators (let's call them decorator_1, decorator_2, etc.) into a single @staticmethod combined_decorator. For my use case, I need the decorators to be able to ...
VRichardJP's user avatar
0 votes
2 answers
104 views

I'm trying to write a tool which will help me find implementation bugs in a large existing python code base that makes heavy use of decorators. Lets say I have a file, rules.py: manager = RuleManager()...
ijustlovemath's user avatar
-1 votes
3 answers
101 views

I'd like to create a decorator that basically wraps an already existing decorator that has parameters, such that the new decorator acts like the old one with some of the arguments supplied. ...
VY_CMa's user avatar
  • 355
0 votes
1 answer
157 views

So I personally favor coding dynamic programming solutions using a top-down approach. Especially in python because it lends itself to a rather easy recursive implementation using the cache decorator, ...
BBenyani's user avatar
  • 123
1 vote
1 answer
180 views

I want to create a decorator that adds a member to the decorated class that is instance of outer class. In this case, decorator memberclass adds attribute self to the instance of class y that is of ...
Superior's user avatar
  • 885
0 votes
1 answer
79 views

Let's say I have a decorator that can be applied to a DRF class based View. A basic version of the decorator i have is as follows:- `class LogRequest: def __init__(self, log_success=True, ...
Adhishraya Sharma's user avatar
1 vote
1 answer
235 views

I cannot find a clean way to structure a python API project that splits the routes of a module (/invoices for this example) into different files, when using a decorator approach for the routing ...
victorperezpiqueras's user avatar
1 vote
1 answer
187 views

I'm writing a logger decorator that can be applied to, among others, classmethods (and theoretically any kind of function or method). My problem is that their parametrization changes according to ...
Gyula Sámuel Karli's user avatar
1 vote
1 answer
52 views

I've surfed some tutorials online about decorators. I'm having trouble seeing their benefit for simple examples. Here is a common example of a function crying out to be decorated, taken from this ...
user2153235's user avatar
  • 1,265
0 votes
1 answer
272 views

In some cases, it is required to inject the same method to multiple classes. To avoid repeated code, I can use a class decorator or class wrapper to assign new attributes and methods to specific class....
cby120's user avatar
  • 23

1
2 3 4 5
51