python / python/mypy

Running mypy on doctests

Open
#7,966 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hi!

I am trying to make a custom tool to run mypy on doctests inside my project.
Because I want to be sure that my examples are correct. And since pytest / doctest modules do it with ease I am seeking the similar solution but for types. Examples, where I need this:

So, I have started with using api. It works fine, but requires to create temp files with extracted doctest code contents. This is a working solution, but the only ugly part is that it is based on temporary files. And reports incorrect filenames, locations, etc.

I have tried to go deeper and pass just the source code / ast parts. But, it does not look like it works this way. Is there a way to make it work without touching a lot of protected / private APIs?

Maybe this can be implemented in mypy itself at sometime?

Thanks!

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 with mypy/api.py and review how its public API accepts source and reports filenames and locations. Compare that behavior with the temporary-file approach described in the issue; the work is done when doctest code can be checked without temporary files while preserving accurate filenames and locations.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
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.