Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docstring of isinstance #68703

Closed
LucSaffre mannequin opened this issue Jun 26, 2015 · 6 comments
Closed

docstring of isinstance #68703

LucSaffre mannequin opened this issue Jun 26, 2015 · 6 comments
Labels
docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@LucSaffre
Copy link
Mannequin

LucSaffre mannequin commented Jun 26, 2015

BPO 24515
Nosy @terryjreedy, @stevendaprano

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2015-07-02.03:58:15.129>
created_at = <Date 2015-06-26.09:49:10.471>
labels = ['type-feature', 'docs']
title = 'docstring of isinstance'
updated_at = <Date 2015-07-02.03:58:15.128>
user = 'https://bugs.python.org/LucSaffre'

bugs.python.org fields:

activity = <Date 2015-07-02.03:58:15.128>
actor = 'steven.daprano'
assignee = 'docs@python'
closed = True
closed_date = <Date 2015-07-02.03:58:15.129>
closer = 'steven.daprano'
components = ['Documentation']
creation = <Date 2015-06-26.09:49:10.471>
creator = 'Luc Saffre'
dependencies = []
files = []
hgrepos = []
issue_num = 24515
keywords = []
message_count = 6.0
messages = ['245841', '245843', '245870', '245871', '245875', '246058']
nosy_count = 4.0
nosy_names = ['terry.reedy', 'steven.daprano', 'docs@python', 'Luc Saffre']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = None
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue24515'
versions = ['Python 2.7', 'Python 3.4', 'Python 3.5', 'Python 3.6']

@LucSaffre
Copy link
Mannequin Author

LucSaffre mannequin commented Jun 26, 2015

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.

@LucSaffre LucSaffre mannequin assigned docspython Jun 26, 2015
@LucSaffre LucSaffre mannequin added docs Documentation in the Doc dir type-feature A feature request or enhancement labels Jun 26, 2015
@stevendaprano
Copy link
Member

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.

@terryjreedy
Copy link
Member

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

@stevendaprano
Copy link
Member

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.

@terryjreedy
Copy link
Member

Right. Close this unless something else is offered.

@stevendaprano
Copy link
Member

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.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants