To elaborate, I've been thinking about how a class decorator expands into something like `cls = decorator(cls)`. A function call. So, why in the hell do most class decorators *mutate* the cls argument in-place as a side effect? (a very non-function kind of thing to do).
I've done this with class decorators in my books, but I'm hardly the only offender. Also class decorators in the standard library (e.g., dataclass) mutate the class. It now just feels off to me.
Decorators shouldn't mutate the wrapped object(s). Perhaps it can work in many cases, but imagine for instance that the underlying instance is an authorized network connection.
I have not seen the "mutate" approach in any actual code, but I am mostly in the Java ecosystem and not Python.
@niclas @dabeaz Decorator in Python can be used on functions and classes. They never wrap objects. So no references exist outside of the decorator, yet.
But now think about using decorators to integrate into a registry of classes. Then developers will get grumpy, if some decorator would generate a copy of the class.