Skip to content Skip to sidebar Skip to footer
Showing posts with the label Decorator

Use A Class Decorator To Implement Late-initialization

I am using some classes which need to connect to databases. The connection is only really needed wh… Read more Use A Class Decorator To Implement Late-initialization

Class Decorator Compatible For Mypy

Say I have the following simple example without any typehints: def wrapper(cls): class Subclass… Read more Class Decorator Compatible For Mypy

Decorator Error: Nonetype Object Is Not Callable

I wrote a function decorator like this: def tsfunc(func): def wrappedFunc(): print '… Read more Decorator Error: Nonetype Object Is Not Callable

How To Access Variables From A Class Decorator From Within The Method It's Applied On?

NOTE I've compiled an answer based on everything written by @AlexHall and @juanpa.arrivillaga. … Read more How To Access Variables From A Class Decorator From Within The Method It's Applied On?

Wrapping Class Method In Try / Except Using Decorator

I have a general purpose function that sends info about exceptions to an application log. I use the… Read more Wrapping Class Method In Try / Except Using Decorator

Python: __qualname__ Of Function With Decorator

I'm using a Decorator (class) in an Instance method of another class, like this: class decorato… Read more Python: __qualname__ Of Function With Decorator

How Do I Decorate An Instance Method With Another Class In Python 2.7?

In Python 2.7 I'd like to decorate an instance method test in class Foo with a decorator that i… Read more How Do I Decorate An Instance Method With Another Class In Python 2.7?

Python: Regular Method And Static Method With Same Name

Introduction I have a Python class, which contains a number of methods. I want one of those methods… Read more Python: Regular Method And Static Method With Same Name

Python Decorator With Arguments And Accessing Class Instance

I have a class defined as follows: class SomeViewController(BaseViewController): @requires('… Read more Python Decorator With Arguments And Accessing Class Instance

Python Decorator For Gae Web-service Security Check

In this post, Nick suggested a decoartor: Python/WebApp Google App Engine - testing for user/pass … Read more Python Decorator For Gae Web-service Security Check

Python: Change Class Type With Decorator And Keep It's Methods

I want to create a class which could be used inside different Applications and their APIs to create… Read more Python: Change Class Type With Decorator And Keep It's Methods

How Much Overhead Do Decorators Add To Python Function Calls

I've been playing around with a timing decorator for my pylons app to provide on the fly timing… Read more How Much Overhead Do Decorators Add To Python Function Calls

Get Decorated Function Object By String Name

def log(func): def wraper(*a, **kw): return func(*a, **kw) return wraper @log d… Read more Get Decorated Function Object By String Name

Functools.update_wrapper() Doesn't Work Properly

I use Functools.update_wrapper() in my decorator, but It seems like update_wrapper rewrites only fu… Read more Functools.update_wrapper() Doesn't Work Properly

Decorators Versus Inheritance

How do you decide between using decorators and inheritance when both are possible? E.g., this probl… Read more Decorators Versus Inheritance

How To Inherit A Flask Methodview Class Without Its Decorators?

For the reason of not rewriting the same API. I want to inherit a get method from an already create… Read more How To Inherit A Flask Methodview Class Without Its Decorators?

How Can I Use A Decorator On A Pyqt Signal?

I have a decorator that is supposed to try / except any method given to the wrapper so that it can … Read more How Can I Use A Decorator On A Pyqt Signal?

Class Decorator For Methods From Other Class

NOTE: I've got a related question here: How to access variables from a Class Decorator from wit… Read more Class Decorator For Methods From Other Class

How To Change A Function's Return Using A Decorator?

I want create a decorator to change a function's return value like that, How to do that like be… Read more How To Change A Function's Return Using A Decorator?

Toggling Decorators

What's the best way to toggle decorators on and off, without actually going to each decoration … Read more Toggling Decorators