Require annotations for all nested functions within an annotated function

Open
#1,324 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
devtools

Research direction

Start by reviewing mypy's current handling of unannotated nested functions inside annotated functions and how strict mode represents related checks. Clarify whether this should be part of strict mode or a separate check, then define tests showing the expected enforcement and completion criteria.

Written by the indexing model from the issue text.

Description

feature needs discussion priority-1-normal

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.)

Dominant language
Python
Stars
20.6k
Forks
3.3k
Avg merge
1d 18h
Merged PRs (30d)
54

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python/mypy

All issues in python/mypy

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.