python / python/mypy

Should we eventually type check all function bodies by default?

Open
#6,646 1 comment 14 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs discussion
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

One of the more surprising mypy features is that is doesn't type check functions without annotations (see #6643 for an example). New users are particularly likely to hit this issue, but it's generally easy to forget to annotate functions, especially those that don't take any arguments. Maybe we should type check all function bodies by default, and provide an option to fall back to the current behavior. We've made this behavior quite prominent in the documentation, but it still seems to confuse many users.

We'd probably want to reduce the number of false positives before making the switch, but this is something the mypy core team is planning to work on anyway. It may be useful to try to infer the return type automatically as well for this to provide the most benefits.

Thoughts?

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.

Research direction

Start by reading the behavior described here and the example in issue #6643, then review the documentation that explains unchecked function bodies. The issue does not name implementation files or tests; done would require a decided approach for default checking, an option for the current behavior, and reduced false positives, with tests and documentation updated accordingly.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.