Top "Decorator" questions

Decorator is an object-oriented design pattern that allows adding behavior to existing classes in a dynamic fashion.

Python decorator best practice, using a class vs a function

As I've understood it there are two ways to do a Python decorator, to either use the __call__ of a …

python python-2.7 decorator syntactic-sugar
Preferred way of defining properties in Python: property decorator or lambda?

Which is the preferred way of defining class properties in Python and why? Is it Ok to use both in …

python lambda properties decorator
ASP.NET MVC Routing Via Method Attributes

In the StackOverflow Podcast #54, Jeff mentions they register their URL routes in the StackOverflow codebase via an attribute above the …

asp.net-mvc routing url-routing decorator
How to build a decorator with optional parameters?

I would like to make a decorator which could be used with or without a parameter : Something like this : class …

python decorator
Making decorators with optional arguments

from functools import wraps def foo_register(method_name=None): """Does stuff.""" def decorator(method): if method_name is None: …

python wrapper decorator
How to use method parameter attributes

I've been struggling to find examples of how to write a custom attribute to validate method parameters, i.e., turn …

c# .net decorator custom-attributes
Python decorator as a staticmethod

I'm trying to write a python class which uses a decorator function that needs information of the instance state. This …

python decorator static-methods
TypeScript: remove key from type/subtraction type

I want to define a generic type ExcludeCart<T> that is essentially T but with a given key (…

reactjs generics typescript decorator higher-order-components
Python: How can I separate functions of class into multiple files?

I know this has been asked a couple of times, but I couldn't quite understand the previous answers and/or …

python file object decorator
Python functools.wraps equivalent for classes

When defining a decorator using a class, how do I automatically transfer over__name__, __module__ and __doc__? Normally, I would …

python decorator