hugapi / hug

Embrace the APIs of the future. Hug aims to make developing APIs as simple as possible, but no simpler.
MIT License
6.86k stars 388 forks source link

TypeError: __call__() missing 1 required positional argument: 'context' #880

Open ptitpoulpe opened 3 years ago

ptitpoulpe commented 3 years ago

If a validator handler raise a TypeError hug catch it believing (here) that’s is an expected error unexpected keyword argument "context"

A solution is to use replace initialize_handler code with something like that:

import inspect
    def initialize_handler(handler, value, context):
        if "context" in inspect.signature(handler).parameters: # It's better to ask for permission than for forgiveness
            return handler(value, context=context)
        else:
            return handler(value)