8000 Use type variable bound when it appears as actual during inference by ilevkivskyi · Pull Request #16178 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Use type variable bound when it appears as actual during inference #16178

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
merged 5 commits into from
Sep 27, 2023
Merged
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
Next Next commit
Merge branch 'master' into infer-upper-bound
  • Loading branch information
hauntsaninja authored Sep 26, 2023
commit 5a3d0f11151689308a9ea09b1f9c68a1591290cb
25 changes: 25 additions & 0 deletions test-data/unit/check-inference.test
Original file line number Diff line number Diff line change
Expand Up @@ -3719,3 +3719,28 @@ ABT = TypeVar("ABT", bound=Union[A, B])

def simpler(k: ABT):
foo(k)


[case testInferenceWorksWithEmptyCollectionsNested]
from typing import List, TypeVar, NoReturn
T = TypeVar('T')
def f(a: List[T], b: List[T]) -> T: pass
x = ["yes"]
reveal_type(f(x, [])) # N: Revealed type is "builtins.str"
reveal_type(f(["yes"], [])) # N: Revealed type is "builtins.str"

empty: List[NoReturn]
f(x, empty) # E: Cannot infer type argument 1 of "f"
f(["no"], empty) # E: Cannot infer type argument 1 of "f"
[builtins fixtures/list.pyi]

[case testInferenceWorksWithEmptyCollectionsUnion]
from typing import Any, Dict, NoReturn, NoReturn, Union

def foo() -> Union[Dict[str, Any], Dict[int, Any]]:
return {}

empty: Dict[NoReturn, NoReturn]
def bar() -> Union[Dict[str, Any], Dict[int, Any]]:
return empty
[builtins fixtures/dict.pyi]
You are viewing a condensed version of this merge commit. You can view the full changes here.
0