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

Fixes type inference for generic calls in if expr #11128

Closed
wants to merge 6 commits into from
Closed

Fixes type inference for generic calls in if expr #11128

wants to merge 6 commits into from

Conversation

sobolevn
Copy link
Member

Closes #11049

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@sobolevn
Copy link
Member Author

mypy_primer output seems related, but it is not directly caused by this change: this also happens on latest master.
Снимок экрана 2021-09-17 в 20 13 02

@sobolevn
Copy link
Member Author

sobolevn commented Sep 18, 2021

Ok, I will try to figure out what is going on. Looks like other commits into master do not produce this problem. 🤔

@sobolevn
Copy link
Member Author

Yes, this problem is reproduced on master with:

from typing import TypeVar, Union, List

T1 = TypeVar("T1")

def promote_list(item: Union[T1, List[T1]]) -> List[T1]:
    ...

exprs: List[int]
reveal_type(promote_list(exprs))

I've opened a new issue: #11149

So, this can be considered as "ready to be reviewed".

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! This seems like a promising approach. I want to check this with our big internal repository before merging, however. Even minor changes to type inference often cause unexpected false positives or other regressions.

mypy/checkexpr.py Outdated Show resolved Hide resolved
@JelleZijlstra
Copy link
Member

FYI this has a merge conflict.

@sobolevn
Copy link
Member Author

@JelleZijlstra thanks! Resolved.

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.

generic incorrectly narrowed based on first parameter in the else branch of an if expression
4 participants