Skip to content

Use information from find_isinstance_check in short-circuit case too #1751

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 1 commit into from

Conversation

rwbarton
Copy link
Contributor

Fixes #1733.

@gvanrossum
Copy link
Member

Probably @ddfisher should review?

@ddfisher
Copy link
Collaborator

I'll take a look tomorrow!

self.chk.binder.push(var, type)
left_type = self.accept(e.left, ctx)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we have to recheck e.left?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One of the tests includes an example where we learn more about the type of an expression when we find out it is true. isinstance(x, A) and x.a has type Union[bool, A] (where x.a : A) but isinstance(x, A) and x.a or A() has type A because for it to evaluate to isinstance(x, A) and x.a, that expression must be true and then it will evaluate to x.a.

In fact, that logic applies to any expression p and q or r even if p is not an isinstance check, so perhaps this isn't a very compelling example.

@ddfisher
Copy link
Collaborator

To the best of my understanding, this is superseded by #1989. The tests for this PR pass after #1989.

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