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 p-ganssle
Recipients ewjoachim, p-ganssle, serhiy.storchaka
Date 2020-02-04.19:49:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1580845771.64.0.511087474562.issue39550@roundup.psfhosted.org>
In-reply-to
Content
Serhiy: I think at least a test for this particular corner case should be added, so that no implementations of `isinstance` that use the CPython test suite hit an infinite recursion in that event, I guess?

Though I think it's maybe an open question as to what the correct behavior is. Should we throw on any tuple subclass because there's no reason to support tuple subclasses? Should we switch to using __iter__ when it's defined because there are other cases where the custom behavior of the subclass is defined by its __iter__? Should we make it a guarantee that __iter__ is *never* called?

I can't really think of a reason why defining __iter__ on a tuple subclass would be anything other than a weird hack, so I would probably say either ban tuple subclasses or add a test like so:

def testIsinstanceIterNeverCalled(self):
    """Guarantee that __iter__ is never called when isinstance is invoked"""
    class NoIterTuple(tuple):
        def __iter__(self):  # pragma: nocover
            raise NotImplemented("Cannot call __iter__ on this.")

    self.assertTrue(isinstance(1, NoIterTuple((int,))))
History
Date User Action Args
2020-02-04 19:49:31p-gansslesetrecipients: + p-ganssle, serhiy.storchaka, ewjoachim
2020-02-04 19:49:31p-gansslesetmessageid: <1580845771.64.0.511087474562.issue39550@roundup.psfhosted.org>
2020-02-04 19:49:31p-gansslelinkissue39550 messages
2020-02-04 19:49:31p-gansslecreate