Stefan Behnel added the comment: > I'm not sure I like the idea that Cython functions are "chimeras" of > some sort, i.e. they have a type of python builtin functions, hence, > logically, Signature.from_builtin should work on them (and they have to > follow __text_signature__ API), and on the other hand, they try to mimic > pure python functions (being a builtin type) with all its guts like > '__code__' object etc.
That's one way of looking at it. The way I see it is that CPython's builtin functions should rather behave exactly like Python functions. The fact that there is such a thing as a "__text_signature__" and general special casing of builtins is IMHO a rather annoying but truly long standing bug. The only necessary difference is that one of them contains byte code and the other doesn't, everything else should eventually be aligned. > Perhaps, what we need to do, is to modify 'Signature.from_builtin' to > check for pure-python function duck type too, and fallback to > 'Signature.from_function' in this case. In any case, I think that a complete Python function(-like) interface should always be preferred to work-arounds like "__text_signature__", regardless of where it comes from. > 'from_builtin' needs to have those type checks. Duck typing is good, but > some minimal type safety is good too. I don't really see why. The code doesn't seem to be doing that much more than text processing of the "__text_signature__", plus a tiny bit of optional(!) attribute checking ("__module__" and "__self__"). The restrictive type checks appear to be the only thing that prevents users from doing this: class myfunc: __text_signature__ = '(a,b,c,d)' sig = Signature.from_builtin(myfunc()) Granted, the name of that method doesn't really fit well in that case, and a simpler interface than having to define a class would also not hurt. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue17159> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com