[Python-Dev] Why does Signature.from_function() have to check the type of its argument? (original) (raw)
Stefan Behnel stefan_ml at behnel.de
Fri Feb 8 15:09:07 CET 2013
- Previous message: [Python-Dev] help with knowledge on how to find which release a fix will land in
- Next message: [Python-Dev] Why does Signature.from_function() have to check the type of its argument?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi,
I'm wondering about the purpose of this code in inspect.Signature.from_function():
""" if not isinstance(func, types.FunctionType): raise TypeError('{!r} is not a Python function'.format(func)) """
Is there any reason why this method would have to explicitly check the type of its argument? Why can't it just accept any object that quacks like a function?
The reason why I ran into this is that I was trying to implement PEP 362 for Cython functions (which are not of Python function type types.FunctionType), and these two lines currently force me to copy the entire method body over into my code, just to build a Signature object from introspection. I find that a really bad design.
Could this check please be removed completely? Or at least be changed to use isfunction() instead, so that it becomes a bit more easy to monkey patch it? (which is hard enough to explain to users already, BTW)
Oh, and that's for 3.3.1, please.
Stefan
- Previous message: [Python-Dev] help with knowledge on how to find which release a fix will land in
- Next message: [Python-Dev] Why does Signature.from_function() have to check the type of its argument?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]