Skip to content

Commit c8b23ac

Browse files
committed
fix
1 parent 99a2063 commit c8b23ac

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

mypy/erasetype.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,12 @@ def visit_unpack_type(self, t: UnpackType) -> ProperType:
101101
def visit_callable_type(self, t: CallableType) -> ProperType:
102102
# We must preserve the fallback type for overload resolution to work.
103103
any_type = AnyType(TypeOfAny.special_form)
104+
ret_type = t.ret_type if t.is_type_obj() else any_type
104105
return CallableType(
105106
arg_types=[any_type, any_type],
106107
arg_kinds=[ARG_STAR, ARG_STAR2],
107108
arg_names=[None, None],
108-
ret_type=any_type,
109+
ret_type=ret_type,
109110
fallback=t.fallback,
110111
is_ellipsis_args=True,
111112
implicit=True,

mypy/meet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ def _type_object_overlap(left: Type, right: Type) -> bool:
588588
def is_overlapping_erased_types(
589589
left: Type, right: Type, *, ignore_promotions: bool = False
590590
) -> bool:
591-
"""The same as 'is_overlapping_erased_types', except the types are erased first."""
591+
"""The same as 'is_overlapping_types', except the types are erased first."""
592592
return is_overlapping_types(
593593
erase_type(left),
594594
erase_type(right),

test-data/unit/check-functools.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,8 @@ def f1(cls: type[A]) -> None:
592592

593593
def f2() -> None:
594594
A() # E: Cannot instantiate abstract class "A" with abstract attribute "method"
595-
partial_cls = partial(A) # E: Cannot instantiate abstract class "A" with abstract attribute "method"
595+
partial_cls = partial(A) # E: Cannot instantiate abstract class "A" with abstract attribute "method" \
596+
# E: Argument 1 to "partial" has incompatible type "Type[A]"; expected "Callable[..., A]"
596597
partial_cls() # E: Cannot instantiate abstract class "A" with abstract attribute "method"
597598
[builtins fixtures/tuple.pyi]
598599

test-data/unit/check-optional.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,3 +1343,19 @@ def f(x: object) -> None:
13431343
with C():
13441344
pass
13451345
[builtins fixtures/tuple.pyi]
1346+
1347+
[case testRefineAwayNoneCallbackProtocol]
1348+
# Regression test for issue encountered in https://github.com/python/mypy/pull/18347#issuecomment-2564062070
1349+
from __future__ import annotations
1350+
from typing import Protocol
1351+
1352+
class CP(Protocol):
1353+
def __call__(self, parameters: str) -> str: ...
1354+
1355+
class NotSet: ...
1356+
1357+
class Task:
1358+
def with_opt(self, trn: CP | type[NotSet] | None):
1359+
if trn is not NotSet:
1360+
reveal_type(trn) # N: Revealed type is "Union[__main__.CP, Type[__main__.NotSet], None]"
1361+
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)