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: issubclass doc improvement
Type: enhancement Stage:
Components: Documentation Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, ezio.melotti, fossilet, iritkatriel, kj
Priority: normal Keywords:

Created on 2012-11-08 14:04 by fossilet, last changed 2022-04-11 14:57 by admin.

Messages (5)
msg175158 - (view) Author: Yongzhi Pan (fossilet) * Date: 2012-11-08 14:04
http://docs.python.org/3/library/functions.html#issubclass

"classinfo may be a tuple of class objects."

I suggest make it clear like isinstance, use something like this:

classinfo may be a tuple of class objects and such tuples.
msg175208 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-11-08 23:46
While this is documented for isinstance, I'm not sure it should be advertised too much, as it seems to me an implementation detail and doesn't seem too useful in practice.

This is a side-effect of the fact that
  isinstance(x, (A, B, ...))
is equivalent to
  isinstance(x, A) or isinstance(x, B) or ...
and therefore
  isinstance(x, (A, (B, C)))
is equivalent to
  isinstance(x, A) or isinstance(x, (B, C))
which in turn is equivalent to
  isinstance(x, A) or (isinstance(x, B) or isinstance(x, C))

While this behavior seems intentional [0], it doesn't seem to be tested [1].  FTR this is supported by PyPy too.

[0]: http://hg.python.org/cpython/file/default/Objects/abstract.c#l2494
[1]: http://hg.python.org/cpython/file/default/Lib/test/test_builtin.py#l704
msg395921 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-06-16 13:52
Whether the recursive nature of the check should be documented or not, it seems inconsistent that it's documented for isinstance but not for issubclass.
msg395942 - (view) Author: Ken Jin (kj) * (Python committer) Date: 2021-06-16 15:49
@irit, you may be interested in issue44135, there's an open PR there and it seems to fix what this issue describes.
msg395979 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-06-17 08:36
@Ken - not quite. This issue is about isinstance containing "(or recursively, other such tuples)" which is not there for issubclass.
History
Date User Action Args
2022-04-11 14:57:38adminsetgithub: 60641
2021-06-17 08:36:23iritkatrielsetmessages: + msg395979
2021-06-16 15:49:57kjsetnosy: + kj
messages: + msg395942
2021-06-16 13:52:10iritkatrielsetnosy: + iritkatriel

messages: + msg395921
versions: + Python 3.11, - Python 3.3, Python 3.4
2012-11-08 23:46:28ezio.melottisettype: enhancement

messages: + msg175208
nosy: + ezio.melotti
2012-11-08 14:04:40fossiletcreate