Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python 3 isinstance

Reply
Thread Tools

Python 3 isinstance

 
 
Lambert, David W (S&T)
Guest
Posts: n/a
 
      01-14-2009
Please, why isn't a set permitted as the second argument to isinstance?
 
Reply With Quote
 
 
 
 
Carl Banks
Guest
Posts: n/a
 
      01-14-2009
On Jan 14, 4:14*pm, "Lambert, David W (S&T)" <Lamber...@Corning.com>
wrote:
> Please, why isn't a set permitted as the second argument to isinstance?


The Python development team might be open to adding it if you were to
submit a patch. The use case is fairly obvious. I doubt any of them
would respond to a wishlist request, though.

As a workaround, you can just cast the set to a tuple like this:

isinstance(x,tuple(s))


Carl Banks
 
Reply With Quote
 
 
 
 
Rhamphoryncus
Guest
Posts: n/a
 
      01-16-2009
On Jan 14, 3:14*pm, "Lambert, David W (S&T)" <Lamber...@Corning.com>
wrote:
> Please, why isn't a set permitted as the second argument to isinstance?


The real problem is it would be misleading. isinstance(a, myset)
suggests implementation like type(a) in myset, but it's really any
(isinstance(a, t) for t in myset).

If myset is arbitrarily large (as the examples suggest), and you're
checking on every call, the code would be so slow as to be considered
broken. This invalidates the use case.

The abc module in 2.6/3.0 is a possible alternative. Create an ABC
type, register each type in myset as part of it, then do isinstance(a,
MyABC). Internally the ABC will cache lookups, effectively getting
you back to O(1) cost.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
isinstance(.., file) for Python 3 Ulrich Eckhardt Python 5 11-08-2012 03:14 PM
Re: Python 3 isinstance Terry Reedy Python 4 01-16-2009 11:07 AM
Re: Python 3 isinstance Lambert, David W (S&T) Python 2 01-15-2009 06:25 AM
Re: isInstance problem Ben Jessel Java 0 07-10-2003 10:26 AM
Re: isInstance problem Joona I Palaste Java 4 07-02-2003 05:48 AM



Advertisments