Skip to content

Fixes type inference for generic calls in if expr#11128

Closed
sobolevn wants to merge 6 commits into
python:masterfrom
sobolevn:issue-11049
Closed

Fixes type inference for generic calls in if expr#11128
sobolevn wants to merge 6 commits into
python:masterfrom
sobolevn:issue-11049

Conversation

@sobolevn

Copy link
Copy Markdown
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
Copy Markdown
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

sobolevn commented Sep 18, 2021

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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".

@JukkaL JukkaL left a comment

Copy link
Copy Markdown
Collaborator

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.

Comment thread mypy/checkexpr.py Outdated
@JelleZijlstra

Copy link
Copy Markdown
Member

FYI this has a merge conflict.

@sobolevn

Copy link
Copy Markdown
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