Skip to content

Fix crash when function annotation has more args than function with fast parser #1812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ def check_function_signature(self, fdef: FuncItem) -> None:
extra_anys = [AnyType()] * (len(fdef.arguments) - len(sig.arg_types))
sig.arg_types.extend(extra_anys)
elif len(sig.arg_types) > len(fdef.arguments):
self.fail('Type signature has too many arguments', fdef)
self.fail('Type signature has too many arguments', fdef, blocker=True)

def visit_class_def(self, defn: ClassDef) -> None:
self.clean_up_bases_and_infer_type_variables(defn)
Expand Down
16 changes: 16 additions & 0 deletions test-data/unit/check-fastparse.test
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,19 @@ def f(a, # type: A
[builtins fixtures/dict.py]
[out]
main: note: In function "f":

[case testFasterParseTooManyArgumentsAnnotation]
# options: fast_parser
def f(): # E: Type signature has too many arguments
# type: (int) -> None
pass
[out]
main: note: In function "f":

[case testFasterParseTooFewArgumentsAnnotation]
# options: fast_parser
def f(x): # E: Type signature has too few arguments
# type: () -> None
pass
[out]
main: note: In function "f":