mypy stub generator
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Mypy stub generator

Mypy requires stub files describing the interfaces of modules in order to type-check code that uses them. Writing them is quite tedious so here are some tools to help:

  • generates a dynamically typed stub file for a named module

  • gets a list of modules to stub by scraping the module index page on (not ideal, I know)


  • CPython version 3
  • Beautiful Soup version 4 if you want to run (get with pip install beautifulsoup4 or apt-get install python3-bs4)


Here's roughly what I did to get a mostly working set of stubs.

Decide what to stub:

python3 > modules.txt

Generate the bulk of the stubs (assuming zsh):

for m (`cat modules.txt`) python3 $m stubs

A couple didn't quite work with the default settings:

rm stubs/{os,tempfile}.py
python3 os stubs --force-package \
    --hiding MutableMapping --hiding _Environ
python3 tempfile stubs --hiding _Random

I had to use the original hand-written stubs for another two:

  • builtins because the generated stub has some syntax errors around the definitions of any and object

  • re because the original stub had some extra interfaces (Match and Pattern, I think) which aren't actually exposed as classes in the python module.