Top "Python-decorators" questions

In Python, decorators are functions that conveniently alter functions, methods or classes using a special syntax.

How to inject variable into scope with a decorator?

[Disclaimer: there may be more pythonic ways of doing what I want to do, but I want to know how …

python scope closures decorator python-decorators
Why no @override decorator in Python to help code readability?

I've been using abstract classes in Python with ABCMeta. When you write an abstract method you tag it with the …

python inheritance python-decorators
how to do a conditional decorator in python

Is it possible to decorator a function conditionally. For example, I want to decorate the function foo() with a timer …

python conditional decorator python-decorators
Flask: Decorator to verify JSON and JSON Schema

I have a flask application with calls expecting JSON payload. Before each call is processed, I have a 2-step error …

python flask decorator jsonschema python-decorators
Python functools lru_cache with class methods: release object

How can I use functools' lru_cache inside classes without leaking memory? In the following minimal example the foo instance …

python caching python-decorators lru functools
How can I decorate an instance method with a decorator class?

Consider this small example: import datetime as dt class Timed(object): def __init__(self, f): self.func = f def __call__(…

python class self python-decorators
Is a Python Decorator the same as Java annotation, or Java with Aspects?

Are Python Decorators the same or similar, or fundamentally different to Java annotations or something like Spring AOP, or Aspect …

java python python-decorators java-annotations
How can I get a Python decorator to run after the decorated function has completed?

I want to use a decorator to handle auditing of various functions (mainly Django view functions, but not exclusively). In …

python decorator python-decorators
descriptor '__init__' of 'super' object needs argument

I'm trying my hand at making an Object-Oriented text-based game in Python, and attempting to implement my first properties and …

python descriptor python-decorators
How do I avoid the "self.x = x; self.y = y; self.z = z" pattern in __init__?

I see patterns like def __init__(self, x, y, z): ... self.x = x self.y = y self.z = z ... quite …

python python-2.7 python-decorators namedtuple python-attrs