8000 [do not merge] Fixes type inference for generic calls in if expr by hauntsaninja · Pull Request #15140 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

[do not merge] Fixes type inference for generic calls in if expr #15140

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

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Merge branch 'master' into issue-11049
  • Loading branch information
sobolevn authored Sep 29, 2021
commit d0ef5e8552b6c24f2838fd8ca74948bcb6595139
9 changes: 7 additions & 2 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3880,7 +3880,13 @@ def analyze_cond_branch(self, map: Optional[Dict[Expression, Type]],
node: Expression, context: Optional[Type],
allow_none_return: bool = False,
is_else: bool = False) -> Type:
with self.chk.binder.frame_context(can_skip=True, fall_through=0):
# We need to be have the correct amount of binder frames.
# Sometimes it can be missing for unreachable left or right parts.
with (
self.chk.binder.frame_context(can_skip=True, fall_through=0)
if len(self.chk.binder.frames) > 1
else self.chk.binder.top_frame_context()
):
if map is not None:
self.chk.push_type_map(map)
if is_else and context is not None and isinstance(node, CallExpr):
Expand All @@ -3893,7 +3899,6 @@ def analyze_cond_branch(self, map: Optional[Dict[Expression, Type]],
call_type = self.accept(node)
if not is_subtype(call_type, context, ignore_type_params=True):
context = None

if map is None:
# We still need to type check node, in case we want to
# process it for isinstance checks later
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.
0