On Thu, Sep 17, 2009 at 08:43:53PM -0700, Paul McNett wrote:
> On a more serious note, rest assured if something practical were affected by 
> our 
> gratuitous use of isinstance(), we'd change it.
> 
> Usually, we don't care if an object supports an interface, we care if the 
> object is 
> an instance of a particular class. Hence, isinstance().

Thats not entirely true. I'd guess(from a quick grep)  your usually
is only about 50-60% of the time.

Take a look at this method from GridSizer,

def setColExpand(self, expand, colNum, proportion=0):
        """ Sets the 'growable' status of one or more columns.  """
        # If the colNum argument was passed first, switch it
        # with the 
        # expand argument
        if isinstance(expand, basestring):
                expand, colNum = colNum, expand
        if isinstance(colNum, (list, tuple)):
                for col in colNum:
                        self.setColExpand(expand, col, proportion) 
        elif isinstance(colNum, basestring):
                if colNum.lower() == "all":
                        for col in xrange(self.HighCol+1):
                                self.setColExpand(expand, col, proportion)
                else:
                        raise ValueError( _("Invalid value passed for 'colNum' 
parameter: '%s'. Only column numbers or the word 'all' are valid.") % colNum)
        else:
                curr = self.getColExpand(colNum)
                self._colExpandState[colNum] = expand
                if expand and not curr:
                        self.AddGrowableCol(colNum, proportion=proportion)
                elif not expand and curr:
                        self.RemoveGrowableCol(colNum)
        self.layout()

My personal view is the first isinstance() eg, the test for tuple or
list is exactly what the article is complaining about. What you seem
to be trying to detect there is wether the colNum provides the 
iteration interface, (eg.  the __iter__() method) a client application
my so some reason use a custom opbject to store the columns.

The tests for string are much more reasonable IMHO, although they 
have there own issues with python3 (which has no basestring defined),
because there you really are testing for what an object is. 

It is a difficult issue, and isinstance is a easy crutch to fall
into using , and I'm sure parts of my own code suffer from this 
as well.

TTFN
-- 
Roger.                          Home| http://www.sandman.uklinux.net/
Master of Peng Shui.      (Ancient oriental art of Penguin Arranging)
Work|Independent Sys Consultant | http://www.computer-surgery.co.uk/
 New key Fpr: 72AF 0ACC 9A53 E59F B1B6  DC14 1983 A13E 5C3D 3CEB 


_______________________________________________
Post Messages to: Dabo-users@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: 
http://leafe.com/archives/byMID/20090918091405.ga29...@computer-surgery.co.uk

Reply via email to