Author scoder
Recipients benjamin.peterson, eric.araujo, larry, ncoghlan, pitrou, python-dev, scoder, terry.reedy, yselivanov
Date 2014-02-01.19:07:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <52ED45E7.60907@behnel.de>
In-reply-to <1391279964.95.0.39325354624.issue17159@psf.upfronthosting.co.za>
Content
> 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.
History
Date User Action Args
2014-02-01 19:07:20scodersetrecipients: + scoder, terry.reedy, ncoghlan, pitrou, larry, benjamin.peterson, eric.araujo, python-dev, yselivanov
2014-02-01 19:07:20scoderlinkissue17159 messages
2014-02-01 19:07:20scodercreate