8000 Extend special case for context-based typevar inference to typevar unions in return position by sterliakov · Pull Request #18976 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Extend special case for context-based typevar inference to typevar unions in return position #18976

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

Merged
Prev Previous commit
Next Next commit
Switch to detecting *any* typevar in union in return position - `T | …
…str` is no less problematic
  • Loading branch information
sterliakov committed Apr 26, 2025
commit 43c097c4e8ee7889ba256a0d161368cc0cf6ab61
8000 2 changes: 1 addition & 1 deletion mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,7 @@ def infer_function_type_arguments_using_context(
if (
isinstance(proper_ret, TypeVarType)
or isinstance(proper_ret, UnionType)
and all(isinstance(get_proper_type(u), TypeVarType) for u in proper_ret.items)
and any(isinstance(get_proper_type(u), TypeVarType) for u in proper_ret.items)
):
# Another special case: the return type is a type variable. If it's unrestricted,
# we could infer a too general type for the type variable if we use context,
Expand Down
Loading
0