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

Fix TypeVar upper bounds sometimes not being displayed in pretty callables #17802

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2942,9 +2942,9 @@ def [T <: int] f(self, x: int, y: T) -> None
for tvar in tp.variables:
if isinstance(tvar, TypeVarType):
upper_bound = get_proper_type(tvar.upper_bound)
if (
if not (
isinstance(upper_bound, Instance)
and upper_bound.type.fullname != "builtins.object"
and upper_bound.type.fullname == "builtins.object"
):
tvars.append(f"{tvar.name}: {format_type_bare(upper_bound, options)}")
elif tvar.values:
Expand Down
14 changes: 14 additions & 0 deletions test-data/unit/check-functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,20 @@ else:
# N: Redefinition: \
# N: def f(x: int = ...) -> None

[case testIncompatibleConditionalFunctionDefinition4]
from typing import Any, Union, TypeVar
T1 = TypeVar('T1')
T2 = TypeVar('T2', bound=Union[int, str])
x = None # type: Any
if x:
def f(x: T1) -> T1: pass
else:
def f(x: T2) -> T2: pass # E: All conditional function variants must have identical signatures \
# N: Original: \
# N: def [T1] f(x: T1) -> T1 \
# N: Redefinition: \
# N: def [T2: Union[int, str]] f(x: T2) -> T2

[case testConditionalFunctionDefinitionUsingDecorator1]
from typing import Callable

Expand Down
Loading