New submission from Anthony Scopatz:
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.
--
components: Library (Lib)
files: abc_rec_fail.py
messages: 285090
nosy: Anthony Scopatz
priority: normal
severity: normal
status: open
title: ABC Recursion Error on isinstance() with less than recursion limit class
hierarchy depth
type: behavior
versions: Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 3.6, Python 3.7
Added file: http://bugs.python.org/file46236/abc_rec_fail.py
___
Python tracker
<http://bugs.python.org/issue29221>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com