Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed Feb 18, 2024
1 parent af75361 commit dc20484
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
3 changes: 2 additions & 1 deletion pyanalyze/name_check_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2083,7 +2083,8 @@ def check_typeis(self, info: FunctionInfo) -> None:
if isinstance(can_assign, CanAssignError):
self._show_error_if_checking(
info.node.returns,
f"TypeIs narrowed type {type_is.guarded_type} is incompatible with parameter {param.name}",
f"TypeIs narrowed type {type_is.guarded_type} is incompatible "
f"with parameter {param.name}",
error_code=ErrorCode.typeis_must_be_subtype,
detail=can_assign.display(),
)
Expand Down
28 changes: 8 additions & 20 deletions pyanalyze/test_typeis.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def main1(a: object) -> None:
def testTypeIsOverload(self):
import collections.abc
from typing import Callable, Iterable, Iterator, List, Optional, TypeVar
from typing_extensions import TypeIs, assert_type, overload
from typing_extensions import TypeIs, overload
from pyanalyze.value import assert_is_value, GenericValue, AnyValue, AnySource

T = TypeVar("T")
Expand Down Expand Up @@ -576,16 +576,10 @@ def with_bool(o: object) -> bool:
return False

accepts_typeguard(with_typeguard)
accepts_typeguard(
with_bool
) # E: Argument 1 to "accepts_typeguard" has incompatible type "Callable[[object], bool]"; expected "Callable[[object], TypeIs[bool]]"
accepts_typeguard(with_bool) # TODO error

different_typeguard(
with_typeguard
) # E: Argument 1 to "different_typeguard" has incompatible type "Callable[[object], TypeIs[bool]]"; expected "Callable[[object], TypeIs[str]]"
different_typeguard(
with_bool
) # E: Argument 1 to "different_typeguard" has incompatible type "Callable[[object], bool]"; expected "Callable[[object], TypeIs[str]]"
different_typeguard(with_typeguard) # TODO error
different_typeguard(with_bool) # TODO error

@assert_passes()
def testTypeIsAsGenericFunctionArg(self):
Expand All @@ -608,15 +602,13 @@ def with_bool(o: object) -> bool:

accepts_typeguard(with_bool_typeguard)
accepts_typeguard(with_str_typeguard)
accepts_typeguard(
with_bool
) # E: Argument 1 to "accepts_typeguard" has incompatible type "Callable[[object], bool]"; expected "Callable[[object], TypeIs[bool]]"
accepts_typeguard(with_bool) # TODO error

@assert_passes()
def testTypeIsAsOverloadedFunctionArg(self):
# https://github.com/python/mypy/issues/11307
from typing import Callable, TypeVar, Generic, Any, overload
from typing_extensions import TypeIs, assert_type
from typing_extensions import TypeIs

_T = TypeVar("_T")

Expand Down Expand Up @@ -670,13 +662,9 @@ def with_typeguard_b(o: object) -> TypeIs[B]:
def with_typeguard_c(o: object) -> TypeIs[C]:
return False

accepts_typeguard(
with_typeguard_a
) # E: Argument 1 to "accepts_typeguard" has incompatible type "Callable[[object], TypeIs[A]]"; expected "Callable[[object], TypeIs[B]]"
accepts_typeguard(with_typeguard_a) # TODO error
accepts_typeguard(with_typeguard_b)
accepts_typeguard(
with_typeguard_c
) # E: Argument 1 to "accepts_typeguard" has incompatible type "Callable[[object], TypeIs[C]]"; expected "Callable[[object], TypeIs[B]]"
accepts_typeguard(with_typeguard_c) # TODO error

@assert_passes()
def testTypeIsWithIdentityGeneric(self):
Expand Down

0 comments on commit dc20484

Please sign in to comment.