logoalt Hacker News

FrameworkFred04/23/20250 repliesview on HN

That's a long read, but it is an awkward thing tbh.

My take on it is that, if you're going to write a decorator, make sure you test it thoroughly and be sure to cover the ways that it will actually be used.

To properly handle a decorator that needed to be called both with and without arguments, I ended up writing a function decorator that returned a wrapped function when there were no parameters provided for the decorator (*args param to the decorator function undefined) and, otherwise, returned an instance of a class that defined __call__ and __init__ methods.

I'm still a bit surprised that I had to do it that way, but that's how it shook out.