On 11/15/06, Jim Jewett <[EMAIL PROTECTED]> wrote:

> (list clipped)

Sorry, I'd rather not get into private conversations.

> On 11/15/06, George Sakkis <[EMAIL PROTECTED]> wrote:
> > Note that this does _not_ disallow duck typing; anyone is perfectly
> > free to define a method len() in a class that does not extend any of
> > the above so that a client can call x.len() successfully.
>
>
> Not if
>     >>> if instance(x, Sequence):
>
> becomes a standard idiom

It doesn't have to, and it shouldn't, become the standard; after all,
whatever you do in the "else:" part of the isinstance check, you can
do in a try/except block. This has nothing to do with type checking
per se, it's a general LBYL vs EAFP error handling strategy. Python in
general encourages the latter and I totally agree, there's no reason
for this to change. In the few cases where LBYL is deemed better and
you'd use isinstance, you can do the same today with
    if hasattr(x, '__getitem__'):
or whatever attributes you need.

George
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to