1

Is there any way in Python to assert properties of a function object? I'd like to say something like: "Given f is a function, assert f takes a keyword parameter called foo".

def example(foo=1):
  pass

def g(f):
  assert f.takes_argument("foo")

g(example)

Yes, I know Python has duck-typing and you wouldn't want to do this exact example above, but I have some weird requirement in a meta-class and it would be very handy.

xorsyst
  • 7,101
  • 5
  • 37
  • 55

0 Answers0