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: docstring of isinstance
Type: enhancement Stage:
Components: Documentation Versions: Python 3.6, Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Luc Saffre, docs@python, steven.daprano, terry.reedy
Priority: normal Keywords:

Created on 2015-06-26 09:49 by Luc Saffre, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (6)
msg245841 - (view) Author: Luc Saffre (Luc Saffre) Date: 2015-06-26 09:49
The docstring of built-in function 'isinstance' should explain that if the classinfo is a tuple, the object must be instance of *any* (not *all*) of the class objects.
msg245843 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2015-06-26 09:58
It already does:

"The form using a tuple, isinstance(x, (A, B, ...)), is a shortcut
for isinstance(x, A) or isinstance(x, B) or ... (etc.)."

If it were "all", it would use "and", not "or".

I don't think any change is needed. Do you have a suggestion for new wording? If not, I'm going to close this issue.
msg245870 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-06-26 21:20
I agree that the tuple explanation if ok.  But "Return whether an object is an instance of a class or of a subclass thereof." (3.5) seems wrong.  I believe 'subclass' should be 'superclass'.
    
>>> class C: pass

>>> class Csub(C): pass

>>> isinstance(C(), Csub)
False
>>> isinstance(Csub(), C)
True
msg245871 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2015-06-26 22:15
On Fri, Jun 26, 2015 at 09:20:18PM +0000, Terry J. Reedy wrote:

> I agree that the tuple explanation if ok.  But "Return whether an 
> object is an instance of a class or of a subclass thereof." (3.5) 
> seems wrong.  I believe 'subclass' should be 'superclass'.

No, the current description is correct.

> >>> class C: pass
> >>> class Csub(C): pass
> >>> isinstance(C(), Csub)
> False

In this case, the instance C() is an instance of a *superclass* of 
Csub, and isinstance returns False.

> >>> isinstance(Csub(), C)
> True

In this case, the instance Csub() is an instance of a *subclass* of C, 
and isinstance returns True.
msg245875 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-06-26 23:42
Right.  Close this unless something else is offered.
msg246058 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2015-07-02 03:58
Closing. If anyone thinks the docs aren't clear enough, and has an alternate version they would like to suggest, you can re-open it.
History
Date User Action Args
2022-04-11 14:58:18adminsetgithub: 68703
2015-07-02 03:58:15steven.dapranosetstatus: open -> closed
resolution: rejected
messages: + msg246058
2015-06-26 23:42:41terry.reedysetmessages: + msg245875
2015-06-26 22:15:00steven.dapranosetmessages: + msg245871
2015-06-26 21:20:18terry.reedysetnosy: + terry.reedy

messages: + msg245870
versions: + Python 3.4, Python 3.5, Python 3.6
2015-06-26 09:58:18steven.dapranosetnosy: + steven.daprano
messages: + msg245843
2015-06-26 09:49:10Luc Saffrecreate