Skip to content
Advertisement

Tag: decorator

How to obtain parameters from decorated imported function?

i’d like to obtain the parameter from the decorated function. It’s a lil bit different from the usual one. Here is the code output: i need fetch: context, 1,2,3(parameters in test_function) in remotable_timer i know the code below can be a potential way to achieve it, but i have to decorate remotable_cache in line anyway. Dose anyone have any idea,

How to pytest that a decorator is assigned to multiple functions

I read somewhere on SO that you should not test the decorator but the functionality of the wrapped function. Nevertheless there might be a shorter way of testing whether a certain decorator is assigned to multiple functions. I have this decorator: I have some tests to test the decorator function itself, e.g.: Now I have about 20 FastAPI endpoints where

How to pass self attributes to a decorator?

I have a decorator for an object method: I want to add another level of wrapping around this to allow parameters: Now, what I want to be able to do is pass a self attribute as a wrapper parameter, i.e. call it with something like this I see 2 options: make self._foo global don’t pass self._foo, and make the decorator

Good way to “wrap” the opening and closing of a database around functions in Python?

I’ve looked at a few related questions on StackOverflow and at some documentation/guides regarding wrappers, all of which tells me “no,” but this doesn’t seem right. That said, I’m very new to programming, so 🤷‍♂️ Problem: Opening and closing a database (using python/sqlite3) requires a tedious amount of repeated code (as I understand it): So, I tried to write a

Advertisement