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 scopatz
Recipients scopatz
Date 2017-01-10.04:18:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1484021927.49.0.387886726852.issue29221@psf.upfronthosting.co.za>
In-reply-to
Content
Classes that have an abstract base class somewhere in their hierarchy have a significantly reduced depth with respect to the recursion limit. In the attached minimal example, the class hierarchy is only able to be 245 deep past the ABC before a recursion error, rather than the expected 1000. 

Also disconcerting is that this recursion error is triggered by unrelated objects, namely an isinstance() check. This means that the error can happen at any point in the interpreter simply because the offending class exists. You don't need to call isinstance() with the offending class.

This is likely due to the way the way that ABCMeta.__subclasscheck__(). This issue can be avoided by either:

1. Not having a deep-ish hierarchy, or 
2. Calling the trigger, isinstance(), each time a new class is created (inside of the loop).

Option (2) works because it tricks ABCMeta into putting each subclass class into its internal cache of subclasses. This fix is undesirable in general because what triggers the error, in general may not be known and can cross package boundaries.

Note: I only tested this on Python v3.4 and v3.5, but it presumably affects all currently supported versions of Python.
History
Date User Action Args
2017-01-10 04:18:47scopatzsetrecipients: + scopatz
2017-01-10 04:18:47scopatzsetmessageid: <1484021927.49.0.387886726852.issue29221@psf.upfronthosting.co.za>
2017-01-10 04:18:47scopatzlinkissue29221 messages
2017-01-10 04:18:46scopatzcreate