[issue24515] docstring of isinstance

New submission from Luc Saffre: 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. ---------- assignee: docs@python components: Documentation messages: 245841 nosy: Luc Saffre, docs@python priority: normal severity: normal status: open title: docstring of isinstance type: enhancement versions: Python 2.7 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue24515> _______________________________________

Steven D'Aprano added the comment: 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. ---------- nosy: +steven.daprano _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue24515> _______________________________________

Terry J. Reedy added the comment: 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
---------- nosy: +terry.reedy versions: +Python 3.4, Python 3.5, Python 3.6 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue24515> _______________________________________

Steven D'Aprano added the comment: On Fri, Jun 26, 2015 at 09:20:18PM +0000, Terry J. Reedy wrote:
No, the current description is correct.
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. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue24515> _______________________________________

Terry J. Reedy added the comment: Right. Close this unless something else is offered. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue24515> _______________________________________

Steven D'Aprano added the comment: 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. ---------- resolution: -> rejected status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue24515> _______________________________________
participants (3)
-
Luc Saffre
-
Steven D'Aprano
-
Terry J. Reedy