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.

classification
Title: isinstance/issubclass doc isn't clear on whether it's an AND or an OR.
Type: enhancement Stage:
Components: Documentation Versions: Python 3.9, Python 3.8, Python 3.7, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: SilentGhost, docs@python, leewz, xtreak
Priority: normal Keywords:

Created on 2019-06-16 11:59 by leewz, last changed 2022-04-11 14:59 by admin.

Messages (7)
msg345744 - (view) Author: Franklin? Lee (leewz) Date: 2019-06-16 11:59
isinstance:
> If classinfo is not a class (type object), it may be a tuple of type objects, or may recursively contain other such tuples (other sequence types are not accepted).

issubclass:
> classinfo may be a tuple of class objects, in which case every entry in classinfo will be checked.

It is unclear from the docs whether
    issubclass(bool, (int, float))
should return True (because bool is a subclass of int),
or False (because bool is NOT a subclass of float).
(It returns True.)

It's likely also false that every entry will be checked, since presumably the function uses short-circuit logic.

issubclass's doc also doesn't mention the recursive tuple case that isinstance's doc has.
msg345747 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2019-06-16 12:23
Where are you seeing the text you've quoted for isinstance? You've marked as all versions affected, but for the master docs the text for isinstance is different and is unambiguous re treatment of tuple classinfo.

I agree with all your points about issubclass
msg345748 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2019-06-16 12:24
> It's likely also false that every entry will be checked, since presumably the function uses short-circuit logic.

This, however, would be good to verify first.
msg345749 - (view) Author: Franklin? Lee (leewz) Date: 2019-06-16 12:29
My mistake. I selected all versions after checking issubclass for 2.7 and several 3.x, but added the isinstance notes later without paying attention to versions.

I copied the isinstance text from 3.2 docs. As you said, it's not the current text.
msg345750 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-06-16 12:32
docstring for issubclass is a bit clear on the behavior


issubclass(cls, class_or_tuple, /)
    Return whether 'cls' is a derived from another class or is the same class.

    A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to
    check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B)
    or ...`` etc.
msg345751 - (view) Author: Franklin? Lee (leewz) Date: 2019-06-16 12:34
> > It's likely also false that every entry will be checked, since presumably the function uses short-circuit logic.

> This, however, would be good to verify first.

Verified.
https://github.com/python/cpython/blob/36dcaab7fde5d2e54cdeff5b705b5adcb27726dd/Objects/abstract.c#L2517

It loops through the tuple until it finds success or error.
msg345752 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2019-06-16 12:37
It's the same behaviour as for isinstance, could be enough to add "classinfo is treated as in isinstance call" to avoid duplication. This would also solve short-cutting imprecision.
History
Date User Action Args
2022-04-11 14:59:16adminsetgithub: 81488
2019-06-21 18:57:28terry.reedysetversions: - Python 3.5, Python 3.6
2019-06-16 12:37:45SilentGhostsetmessages: + msg345752
2019-06-16 12:34:32leewzsetmessages: + msg345751
2019-06-16 12:32:03xtreaksetnosy: + xtreak
messages: + msg345750
2019-06-16 12:29:23leewzsetmessages: + msg345749
2019-06-16 12:24:53SilentGhostsetmessages: + msg345748
2019-06-16 12:23:06SilentGhostsetnosy: + SilentGhost
messages: + msg345747
2019-06-16 11:59:07leewzcreate