Hacker News new | ask | show | jobs
by trentonstrong 5146 days ago
Interesting! This seems like something that might work well with 3.0's function annotation support with the ability to specify that the handler's input argument conform to either a the streaming or buffered interface.

As a point of curiosity about best practices, how are you handling the meta information right now?

It feels like decorators provide the cleanest solution currently, but I've always wondered if there are alternatives.

1 comments

> Interesting! This seems like something that might work well with 3.0's function annotation support with the ability to specify that the handler's input argument conform to either a the streaming or buffered interface.

I thought so, but the annotations in Python 3 are largely useless. They would work if you could forward the signatures through a chain of decorators, but ther is no guarantee for that. I did play around with Python 3 but it's actually not in any way better for what we're doing here.

> It feels like decorators provide the cleanest solution currently, but I've always wondered if there are alternatives.

Decorators require a routing system that can resolve routing "dependencies". We're using the Werkzeug routing which was designed to do that. The basic idea is that it does not matter in which order you define the URL rules, the routing system figures out the ordering.

If you don't have that, you would have to move the definitions to a central file (akin to urls.py in Django) to make this work because you need to define the ordering.

We also experimented with having the meta information in JSON files but it was not really worth it. Having it next to the function makes it easier to maintain it.