-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Require annotations for all nested functions within an annotated function #1324
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
Comments
This seems like the kind of thing that might be better disallowed with |
Hm, `--disallow-untyped-defs` is too big a hammer for this. I think it's
reasonable to suggest that nested functions (excluding lambdas) inside an
annotated function should also be annotated -- just like it insists on
knowing the type of e.g. empty containers in such a context.
|
@danielrh ran into this the other day -- he thought he'd put types on everything in a file, and was surprised when mypy didn't catch a type error he'd made. It turned out that the line of code that had the error was inside a nested function which hadn't been annotated. One way to prevent that would have been to be able to apply This could be an option at first (perhaps even already on by default?) to facilitate migration, but I suspect people will generally be glad to just always do it and it should ultimately be the only way. |
Increasing priority since this is something that I encounter every now and then. |
Mypy currently treats an unannotated function within an annotated function as being dynamically typed, similar to all unannotated functions. However, this can be unexpected, and it's easy to miss nested functions when annotating code because they aren't visually prominent. Perhaps mypy should enforce that nested function are annotated within an annotated function?
Once we have strict mode, it could be used to enforce this as well, but it might be useful have a separate check for this.
(This was suggested by Alex Allain.)
The text was updated successfully, but these errors were encountered: