python / python/mypy

(🎁) Option to not report errors from stub bodies

Open
#12,196 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature priority-2-low
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

test.py:

import foo
foo.foo("")

stubs/foo/init.pyi:

def foo(i: int) -> None:
    1 + ""

mypy test.py

stubs/foo/__init__.pyi:2: error: Unsupported operand types for + ("int" and "str")
test.py:2: error: Argument 1 to "foo" has incompatible type "str"; expected "int"
Found 2 errors in 2 files (checked 1 source file)

In when I'm working with mypy I basically copy-paste the src of libraries into a stubs folder and gradually type them as needed, but it's a pain when I get errors on the bodies of functions like

stubs/x/y/z.pyi error: Call to untyped function "amongus" in typed context  [no-untyped-call]

The bodies of stub functions shouldn't need to be typechecked imo and there should be an option to disable this.

I don't delete the bodies of the functions because that would be a lot of work, and it is kinda convinient that the impl and types are in the same place.

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

Use the test.py and stubs/foo/init.pyi reproducer and run mypy test.py. Trace how diagnostics from stub function bodies are produced, then verify an option suppresses those diagnostics while retaining the call-site argument error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.