Skip to content

Commit d86f5f6

Browse files
ddfishergvanrossum
authored andcommitted
Fix crash when function annotation has more args than function (#1812)
1 parent be0e8f2 commit d86f5f6

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

mypy/semanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ def check_function_signature(self, fdef: FuncItem) -> None:
542542
extra_anys = [AnyType()] * (len(fdef.arguments) - len(sig.arg_types))
543543
sig.arg_types.extend(extra_anys)
544544
elif len(sig.arg_types) > len(fdef.arguments):
545-
self.fail('Type signature has too many arguments', fdef)
545+
self.fail('Type signature has too many arguments', fdef, blocker=True)
546546

547547
def visit_class_def(self, defn: ClassDef) -> None:
548548
self.clean_up_bases_and_infer_type_variables(defn)

test-data/unit/check-fastparse.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,19 @@ def f(a, # type: A
154154
[builtins fixtures/dict.py]
155155
[out]
156156
main: note: In function "f":
157+
158+
[case testFasterParseTooManyArgumentsAnnotation]
159+
# options: fast_parser
160+
def f(): # E: Type signature has too many arguments
161+
# type: (int) -> None
162+
pass
163+
[out]
164+
main: note: In function "f":
165+
166+
[case testFasterParseTooFewArgumentsAnnotation]
167+
# options: fast_parser
168+
def f(x): # E: Type signature has too few arguments
169+
# type: () -> None
170+
pass
171+
[out]
172+
main: note: In function "f":

0 commit comments

Comments
 (0)