code: def apply_ctx(fn, ctx):
      
      if 'ctx' in get_args(fn):
          return functools.partial(fn, ctx=ctx)
      else:
          return fn
docs: Return fn with ctx partially applied, if requested.
  
      If the `fn` callable accepts an argument named "ctx", returns a
      functools.partial object with ctx=ctx applied, else returns `fn` unchanged.
  
      For this to work, the 'ctx' argument must come after any arguments that are
      passed as positional arguments. For example, 'ctx' must be the 2nd argument
      for request handlers, serializers and deserializers, that are always called
      with one positional argument (the request, object to serialize, and input
      filehandle, respectively).