Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix false unreachable error reports. - #9909

Merged
hauntsaninja merged 1 commit into
python:masterfrom
tyralla:fix/isinstance_unreachable
Aug 4, 2021
Merged

Fix false unreachable error reports.#9909
hauntsaninja merged 1 commit into
python:masterfrom
tyralla:fix/isinstance_unreachable

Conversation

@tyralla

@tyralla tyralla commented Jan 13, 2021

Copy link
Copy Markdown
Collaborator

Fixes #9907

For explanations, please see the commit message.

I hope changing the signature of method TypeChecker.intersect_instances is acceptable.

So far, method `TypeChecker.intersect_instances` generally reports an unreachable error for statements like `isinstance(a, B)` when `class C(A, B)` is unsafe without checking if `class C(B, A)` could be safe.

This commit solves this by performing the "reversed" check only if the usual one fails.  Hence, other functionalities and performance should not be affected.

The new test case `testIsInstanceAdHocIntersectionReversed` demonstrates the new functionality.

Note that this commit changes the type of argument `instances`.  It is now `Tuple[Instance, Instance]` instead of `Sequence[Instance]`.  Supporting an arbitrary number of `Instance` objects would require stronger code modifications.
Comment thread mypy/checker.py

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but I'd also want @JukkaL to review this.

@hauntsaninja
hauntsaninja merged commit 21991cf into python:master Aug 4, 2021
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.

unreachable: false positive for isinstance

3 participants