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

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

Decorating A Class To Monitor Attribute Changes

I want to have classes that automatically send notifications to subscribers whenever one of their a… Read more Decorating A Class To Monitor Attribute Changes

Typeerror: 'nonetype' Object Is Not Iterable When Applying Decorator To Generator

I have a decorator function which I want to apply to both normal function and a generator. When app… Read more Typeerror: 'nonetype' Object Is Not Iterable When Applying Decorator To Generator

Python Lru Cache Decorator Per Instance

Using the LRU Cache decorator found here: http://code.activestate.com/recipes/578078-py26-and-py30-… Read more Python Lru Cache Decorator Per Instance

Parsing Args And Kwargs In Decorators

I've got a function that takes args and kwargs, and I need to do something in my decorator base… Read more Parsing Args And Kwargs In Decorators

Python Resettable Instance Method Memoization Decorator

I'm attempting to build a decorator for an instance method of a class that will memoize the res… Read more Python Resettable Instance Method Memoization Decorator

Python Decorator Also For Undefined Attributes

I'd like to create a Model Class for an User. The data of the user are stored in an document ba… Read more Python Decorator Also For Undefined Attributes

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

Decorators In The Python Standard Lib (@deprecated Specifically)

I need to mark routines as deprecated, but apparently there's no standard library decorator for… Read more Decorators In The Python Standard Lib (@deprecated Specifically)

How To Modify Class __dict__ (a Mappingproxy)?

I want to apply a decorator to every method in a class. I don't have source code of the class, … Read more How To Modify Class __dict__ (a Mappingproxy)?

Is There A Way To Run A Method Automatically On The Initialization Of An Instance Without Using __init__?

I am writing some unit tests with Pytest. If I want them to be collected automatically, I have to … Read more Is There A Way To Run A Method Automatically On The Initialization Of An Instance Without Using __init__?

Why Are Decorator Functions Designed In The Way They Are?

It was bothering me for a long time. Why are decorator functions designed like that, they seem to m… Read more Why Are Decorator Functions Designed In The Way They Are?

Tracking Recursion Depth With Python Decorators

I am trying to write a decorator that tracks the recursion depth of a recursive function in Python.… Read more Tracking Recursion Depth With Python Decorators

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

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?

Whether The Return Value Of A Function Modified By Python Decorator Can Only Be Nonetype

I wrote a decorator that gets the runtime of the program, but the function return value becomes Non… Read more Whether The Return Value Of A Function Modified By Python Decorator Can Only Be Nonetype

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?

Java: Automatic Memoization

I have a few functions in my code where it makes much sense (seems even mandatory) to use memoizati… Read more Java: Automatic Memoization

Flask-Login Breaks When My Decorator Accepts Parameters

Thanks to what I learned from this question, I've been able to make a Flask-Login process with … Read more Flask-Login Breaks When My Decorator Accepts Parameters

Python Convert Args To Kwargs

I am writing a decorator that needs to call other functions prior to call of the function that it i… Read more Python Convert Args To Kwargs