Hacker News new | ask | show | jobs
by ojii 422 days ago
One tiny correction:

> decorators are functions that take a callable argument and return a new callable

there's nothing forcing a decorator to return a callable. A decorator _could_ return anything it wants. I don't know why you would want that, but Python won't stop you.

1 comments

They also don’t have to act on callables, see @dataclass for instance.
Classes are callable.
You can abuse this fact with type hunting to get a ParamSpec of a class's __init__ arguments.

But yeah type systems get weird at the margins. Your class is an instance of type which has a __call__ method which creates an instance of your class.