[Python-3000] PEP 3100 Comments

Talin talin at acm.org
Mon May 8 08:58:39 CEST 2006


Greg Ewing wrote:

> Talin wrote:
> 
>> How about instead of 'callable', an "isFunction' test to go along
>> with 'isSequence' and 'isMapping'. (You aren't getting rid of those -
>> I hope...?)
> 
> 
> Yes, we are! And for much the same reasons!

I'll have more to say on this later - but for now, lets just say that 
from what I have seen so far, Py3K's ability to do interface discovery 
seems to be limited to just isinstance(), which essentially means that 
you can't do interface discovery on any type that doesn't have a formal 
interface; And since the whole point of duck typing (in fact, the very 
definition of duck typing) is to not have a formal interface, I think 
that this creates a rather large disconnect, and in particular it makes 
duck typing a second class citizen to formalized typing.

Before we go to much further on this point, I want to get a sense of 
what exactly people are objecting to:

    -- Are they saying that interface discovery is not important, or is 
bad style? (Its hard to do general transformations of objects from one 
form to another without it.)

    -- Are they saying that the way isSequence and such implements 
interface discovery is wrong, and if it is, what's the alternative?

    -- Are they saying that interface discovery should be limited to 
formal types only, and not implicitly defined "duck types"?

    -- Are they proposing some different model of interface discovery 
that they feel is better?

    -- Are they saying that duck types are wrong?

> And *how* exactly would you implement your isFunction test
> so as to detect the "naive, everyday concept of a function"
> that you seem to want, in a way that does any better job
> than the current callable()?

This 'isFunction' test that I am thinking of would only return true for 
user defined functions, built-in functions, and similar objects; It 
would not return true for classes or other objects that are technically 
functions in a mathematically pure sense, but which normal people don't 
think of as functions.

In other words, a function that does what most people expect it to, by 
conforming to their intuitive idea of what a function is, rather than 
some grammatical or mathematical definition. And in cases of ambiguity, 
it would be conservative, returning false negatives but not false positives.

-- Talin


More information about the Python-3000 mailing list