[Patches] [ python-Patches-649608 ] tuple arg for issubclass

noreply@sourceforge.net noreply@sourceforge.net
Sat, 07 Dec 2002 03:57:15 -0800


Patches item #649608, was opened at 2002-12-06 17:32
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=649608&group_id=5470

Category: Core (C code)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Walter Dörwald (doerwalter)
Assigned to: Nobody/Anonymous (nobody)
Summary: tuple arg for issubclass

Initial Comment:
The following patch enhances issubclass(), so that it's
possible to pass a tuple as the second argument. This
has the same meaning as for isinstance(): the first
argument will be checked against each entry in the tuple.

The patch works somewhat differently than isinstance,
because for isinstance, a tuple argument is unpacked
recursively, this patch doesn't do this, instead any
entry in the tuple that isn't a class raises a TypeError.

----------------------------------------------------------------------

>Comment By: Walter Dörwald (doerwalter)
Date: 2002-12-07 12:57

Message:
Logged In: YES 
user_id=89016

I don't see why this should be more confusing than a tuple 
argument for isinstance.

Guido himself was wondering whether he should implement 
this feature (see http://mail.python.org/pipermail/python-
dev/2001-October/017813.html), but it was dropped because 
of to much work and to few benefits. The work is done and 
there there same benefits as with isinstance. In my own code 
I often have to do the following check:

if isinstance(x, type) and (issubclass(x, Element) or 
issubclass(x, ProcInst) or issubclass(x, Entity) or issubclass
(x, CharRef) or issubclass(x, Attr)):

With the patch this could be greatly simplified to:

classes = (Element, ProcInst, Entity, CharRef, Attr)
if isinstance(x, type) and issubclass(x, classes):

(with classes being defined only once)


----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2002-12-07 09:42

Message:
Logged In: YES 
user_id=21627

-1. I find this confusing: one may expect that issubclass(a,
(b,c)) is true iff a is a subclass of both b and c. In the
face of ambiguity, refuse the temptation to guess.

What is the rationale for this feature, apart from symmetry
with isinstance?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=649608&group_id=5470