8000 Disallow to use `TypeGuard` type outside of `.ret_type`, refs #11765 by sobolevn · Pull Request #11790 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Disallow to use TypeGuard type outside of .ret_type, refs #11765 #11790

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

Closed
wants to merge 2 commits into from
Closed
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
Addresses review
  • Loading branch information
sobolevn committed Dec 18, 2021
commit 6723a619d7f9215d6f1356a63eab41bcfc591b4a
4 changes: 4 additions & 0 deletions test-data/unit/check-typeguard.test
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ def main(a: object, b: object) -> None:
[builtins fixtures/tuple.pyi]

[case testTypeGuardIsBool]
from typing import List
from typing_extensions import TypeGuard
def f(a: TypeGuard[int]) -> None: # E: TypeGuard must only be used as a return type
pass
reveal_type(f) # N: Revealed type is "def (a: builtins.bool)"
def f1() -> List[TypeGuard[int]]: # E: TypeGuard must only be used as a return type
pass
reveal_type(f1()) # N: Revealed type is "builtins.list[builtins.bool]"
a: TypeGuard[int] # E: TypeGuard must only be used as a return type
reveal_type(a) # N: Revealed type is "builtins.bool"
class C:
Expand Down
0