This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients georg.brandl, terry.reedy
Date 2009-02-13.18:03:36
SpamBayes Score 6.423924e-06
Marked as misclassified No
Message-id <1234548219.84.0.437841096999.issue5250@psf.upfronthosting.co.za>
In-reply-to
Content
http://www.python.org/dev/peps/pep-3119/#overloading-isinstance-and-issubclass
(GvR and Talin)
"The primary mechanism proposed here is to allow overloading the
built-in functions isinstance() and issubclass(). The overloading works
as follows: The call isinstance(x, C) first checks whether
C.__instancecheck__ exists, and if so, calls C.__instancecheck__(x)
instead of its normal implementation. Similarly, the call issubclass(D,
C) first checks whether C.__subclasscheck__ exists, and if so, calls
C.__subclasscheck__(D) instead of its normal implementation."

These two new special methods are not documented (for 3.x at least.  A
post on python-list today verifies that at least .__instancecheck__ was
implemented (version not specified).  I assume .__subclasscheck__ was
also.  This issue perhaps applies to 2.6/2.7 also.

I suggest either adding "Customizing instance and subclass checks" after
"Customizing class creation" or add to that section and rename it to
"Customizing class creation and checks" since the needed addition seems
too small for its own section.  Something like

The result of isinstance(object, class) can be modified by giving the
*class* a .__instancecheck__(object) method.  The result of
issubclass(sub,super) can be modified by giving the *superclass* a
.__subclasscheck__(sub) method.
History
Date User Action Args
2009-02-13 18:03:40terry.reedysetrecipients: + terry.reedy, georg.brandl
2009-02-13 18:03:39terry.reedysetmessageid: <1234548219.84.0.437841096999.issue5250@psf.upfronthosting.co.za>
2009-02-13 18:03:38terry.reedylinkissue5250 messages
2009-02-13 18:03:36terry.reedycreate