[Patches] [ python-Patches-1708353 ] Make isinstance/issubclass overloadable

SourceForge.net noreply at sourceforge.net
Thu Apr 26 22:34:23 CEST 2007


Patches item #1708353, was opened at 2007-04-26 16:16
Message generated for change (Comment added) made by gvanrossum
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1708353&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Core (C code)
Group: Python 3000
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Guido van Rossum (gvanrossum)
Assigned to: Guido van Rossum (gvanrossum)
Summary: Make isinstance/issubclass overloadable

Initial Comment:
I came up with a fairly simple way to overload isinstance() and issubclass().  The class that is the second argument can define a (class) method named __instancecheck__ or __subclasscheck__ which, if present, will be called *instead* of the normal approach.

The names are different to remind users that the calling convention is the opposite -- isinstance(x, C) maps to C.__instancecheck__(x).


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

>Comment By: Guido van Rossum (gvanrossum)
Date: 2007-04-26 16:34

Message:
Logged In: YES 
user_id=6380
Originator: YES

Oops, forget the first attempt; isinstance(Integer(), Integer) would be
False!  Now it's True, and more tests are added.
File Added: typechecks.diff

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

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


More information about the Patches mailing list