Skip to content

Commit 29d17c1

Browse files
committed
less ambitious
1 parent 9c1d80d commit 29d17c1

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

mypy/typeops.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,10 @@ def callable_corresponding_argument(
529529
not (by_name.required or by_pos.required)
530530
and by_pos.name is None
531531
and by_name.pos is None
532+
# This is not principled, but prevents a crash. It's weird to have a FormalArgument
533+
# that has an UnpackType.
534+
and not isinstance(by_name.typ, UnpackType)
535+
and not isinstance(by_pos.typ, UnpackType)
532536
):
533537
return FormalArgument(
534538
by_name.name, by_pos.pos, meet_types(by_name.typ, by_pos.typ), False

mypy/types.py

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,27 +1923,6 @@ def __hash__(self) -> int:
19231923
return hash((self.name, self.pos, self.typ, self.required))
19241924

19251925

1926-
def _synthesize_arg_from_vararg(
1927-
vararg: FormalArgument | None, position: int | None
1928-
) -> FormalArgument | None:
1929-
if vararg is None:
1930-
return None
1931-
typ = vararg.typ
1932-
if isinstance(typ, UnpackType):
1933-
# Similar to logic in ExpressionChecker.visit_tuple_index_helper
1934-
unpacked = get_proper_type(typ.type)
1935-
if isinstance(unpacked, TypeVarTupleType):
1936-
bound = get_proper_type(unpacked.upper_bound)
1937-
assert isinstance(bound, Instance)
1938-
assert bound.type.fullname == "builtins.tuple"
1939-
typ = bound.args[0]
1940-
else:
1941-
assert isinstance(unpacked, Instance)
1942-
assert unpacked.type.fullname == "builtins.tuple"
1943-
typ = unpacked.args[0]
1944-
return FormalArgument(None, position, typ, False)
1945-
1946-
19471926
class Parameters(ProperType):
19481927
"""Type that represents the parameters to a function.
19491928
@@ -2090,7 +2069,11 @@ def try_synthesizing_arg_from_kwarg(self, name: str | None) -> FormalArgument |
20902069
return None
20912070

20922071
def try_synthesizing_arg_from_vararg(self, position: int | None) -> FormalArgument | None:
2093-
return _synthesize_arg_from_vararg(self.var_arg(), position)
2072+
var_arg = self.var_arg()
2073+
if var_arg is not None:
2074+
return FormalArgument(None, position, var_arg.typ, False)
2075+
else:
2076+
return None
20942077

20952078
def accept(self, visitor: TypeVisitor[T]) -> T:
20962079
return visitor.visit_parameters(self)
@@ -2435,7 +2418,11 @@ def try_synthesizing_arg_from_kwarg(self, name: str | None) -> FormalArgument |
24352418
return None
24362419

24372420
def try_synthesizing_arg_from_vararg(self, position: int | None) -> FormalArgument | None:
2438-
return _synthesize_arg_from_vararg(self.var_arg(), position)
2421+
var_arg = self.var_arg()
2422+
if var_arg is not None:
2423+
return FormalArgument(None, position, var_arg.typ, False)
2424+
else:
2425+
return None
24392426

24402427
@property
24412428
def items(self) -> list[CallableType]:

0 commit comments

Comments
 (0)