Skip to content

Commit

Permalink
Fix crash on a callable attribute with single unpack
Browse files Browse the repository at this point in the history
  • Loading branch information
ilevkivskyi committed Aug 4, 2024
1 parent b56f357 commit b883d82
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mypy/typeops.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,14 @@ class B(A): pass
if not func.arg_types:
# Invalid method, return something.
return cast(F, func)
if func.arg_kinds[0] == ARG_STAR:
if func.arg_kinds[0] in (ARG_STAR, ARG_STAR2):
# The signature is of the form 'def foo(*args, ...)'.
# In this case we shouldn't drop the first arg,
# since func will be absorbed by the *args.

# TODO: infer bounds on the type of *args?

# In the case of **kwargs we should probably emit an error, but
# for now we simply skip it, to avoid crashes down the line.
return cast(F, func)
self_param_type = get_proper_type(func.arg_types[0])

Expand Down
18 changes: 18 additions & 0 deletions test-data/unit/check-typeddict.test
Original file line number Diff line number Diff line change
Expand Up @@ -3579,6 +3579,24 @@ class Test:
run(test2, other=0, **params) # E: Argument "other" to "run" has incompatible type "int"; expected "str"
[builtins fixtures/tuple.pyi]

[case testTypedDictUnpackSingleWithSubtypingNoCrash]
from typing import Callable
from typing_extensions import TypedDict, Unpack

class Kwargs(TypedDict):
name: str

def f(**kwargs: Unpack[Kwargs]) -> None:
pass

class C:
d: Callable[[Unpack[Kwargs]], None]

# TODO: it is an old question whether we should allow this, for now simply don't crash.
class D(C):
d = f
[builtins fixtures/tuple.pyi]

[case testTypedDictInlineNoOldStyleAlias]
# flags: --enable-incomplete-feature=InlineTypedDict
X = {"int": int, "str": str}
Expand Down

0 comments on commit b883d82

Please sign in to comment.