Skip to content

Added Optional annotation for first parameter of object.isinstance #2839

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

Closed
wants to merge 2 commits into from

Conversation

erictraut
Copy link
Contributor

Added Optional annotation for first parameter of object.isinstance because it's able to accept None as a value.

@srittau
Copy link
Collaborator

srittau commented Mar 10, 2019

This is a no-op, since None is a valid instance of object. Type checkers should already accept isinstance(None, ...). Do you have an example where this leads to problems?

@erictraut
Copy link
Contributor Author

Why would None be a valid instance of object? Is this documented? I don't see where in the specs (pep 484 or elsewhere) where this is documented.

If None is a valid instance of object, is it possible to specify that a parameter must be an object but not None?

@srittau
Copy link
Collaborator

srittau commented Mar 10, 2019

None being an instance of object is just the result of Python's type system, where object is at the root of the type hierarchy:

>>> isinstance(None, object)
True
>>> type(None)
<class 'NoneType'>
>>> type(None).__bases__
(<class 'object'>,)

I don't think it's currently possible to allow any value except None. Cf. python/typing#614

@erictraut
Copy link
Contributor Author

Thanks for the explanation. I was under the impression that None was a specialized type not derived from object. Closing the PR.

@erictraut erictraut closed this Mar 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants