Skip to content

Commit 986947a

Browse files
Merge branch 'master' into patch-3
2 parents 4698a87 + 9934278 commit 986947a

File tree

5 files changed

+29
-18
lines changed

5 files changed

+29
-18
lines changed

mypy/checkexpr.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2684,9 +2684,12 @@ def check_arg(
26842684
context=context,
26852685
outer_context=outer_context,
26862686
)
2687-
self.msg.incompatible_argument_note(
2688-
original_caller_type, callee_type, context, parent_error=error
2689-
)
2687+
if not caller_kind.is_star():
2688+
# For *args and **kwargs this note would be incorrect - we're comparing
2689+
# iterable/mapping type with union of relevant arg types.
2690+
self.msg.incompatible_argument_note(
2691+
original_caller_type, callee_type, context, parent_error=error
2692+
)
26902693
if not self.msg.prefer_simple_messages():
26912694
self.chk.check_possible_missing_await(
26922695
caller_type, callee_type, context, error.code

mypy/checkmember.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,23 +1477,18 @@ def bind_self_fast(method: F, original_type: Type | None = None) -> F:
14771477
items = [bind_self_fast(c, original_type) for c in method.items]
14781478
return cast(F, Overloaded(items))
14791479
assert isinstance(method, CallableType)
1480-
func: CallableType = method
1481-
if not func.arg_types:
1480+
if not method.arg_types:
14821481
# Invalid method, return something.
14831482
return method
1484-
if func.arg_kinds[0] in (ARG_STAR, ARG_STAR2):
1483+
if method.arg_kinds[0] in (ARG_STAR, ARG_STAR2):
14851484
# See typeops.py for details.
14861485
return method
1487-
original_type = get_proper_type(original_type)
1488-
if isinstance(original_type, CallableType) and original_type.is_type_obj():
1489-
original_type = TypeType.make_normalized(original_type.ret_type)
1490-
res = func.copy_modified(
1491-
arg_types=func.arg_types[1:],
1492-
arg_kinds=func.arg_kinds[1:],
1493-
arg_names=func.arg_names[1:],
1486+
return method.copy_modified(
1487+
arg_types=method.arg_types[1:],
1488+
arg_kinds=method.arg_kinds[1:],
1489+
arg_names=method.arg_names[1:],
14941490
is_bound=True,
14951491
)
1496-
return cast(F, res)
14971492

14981493

14991494
def has_operator(typ: Type, op_method: str, named_type: Callable[[str], Instance]) -> bool:

mypy/subtypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2117,7 +2117,7 @@ def covers_at_runtime(item: Type, supertype: Type) -> bool:
21172117
supertype = get_proper_type(supertype)
21182118

21192119
# Since runtime type checks will ignore type arguments, erase the types.
2120-
if not (isinstance(supertype, CallableType) and supertype.is_type_obj()):
2120+
if not (isinstance(supertype, FunctionLike) and supertype.is_type_obj()):
21212121
supertype = erase_type(supertype)
21222122
if is_proper_subtype(
21232123
erase_type(item), supertype, ignore_promotions=True, erase_instances=True

mypy/typeops.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,6 @@ class B(A): pass
472472
else:
473473
variables = func.variables
474474

475-
original_type = get_proper_type(original_type)
476-
if isinstance(original_type, CallableType) and original_type.is_type_obj():
477-
original_type = TypeType.make_normalized(original_type.ret_type)
478475
res = func.copy_modified(
479476
arg_types=func.arg_types[1:],
480477
arg_kinds=func.arg_kinds[1:],

test-data/unit/check-functions.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3694,3 +3694,19 @@ def defer() -> int: ...
36943694
[out]
36953695
main: note: In function "a":
36963696
main:6: error: Unsupported operand types for + ("int" and "str")
3697+
3698+
[case testNoExtraNoteForUnpacking]
3699+
from typing import Protocol
3700+
3701+
class P(Protocol):
3702+
arg: int
3703+
# Something that list and dict also have
3704+
def __contains__(self, item: object) -> bool: ...
3705+
3706+
def foo(x: P, y: P) -> None: ...
3707+
3708+
args: list[object]
3709+
foo(*args) # E: Argument 1 to "foo" has incompatible type "*list[object]"; expected "P"
3710+
kwargs: dict[str, object]
3711+
foo(**kwargs) # E: Argument 1 to "foo" has incompatible type "**dict[str, object]"; expected "P"
3712+
[builtins fixtures/dict.pyi]

0 commit comments

Comments
 (0)