ANN: make_stub_files 0.1

Edward K. Ream edreamleo at
Thu Mar 31 07:31:54 EDT 2016

​ ​
0.1 is now available here <>.

This script eliminates much of the drudgery of creating python stub (.pyi)
<> from python source
files. This script should encourage more people to use mypy. Stub files can
be used by people who use Python 2.x code bases.

This script makes a stub (.pyi) file in the output directory for each
source file listed on the command line (wildcard file names are supported).
This script never creates directories automatically, nor does it overwrite
stub files unless the --overwrite command-line option is in effect.

GvR says,

We actually do have a stub generator
<> as part of
mypy now (it has a few options) but yours has the advantage of providing a
way to tune the generated signatures...This allows for a nice iterative way
of developing stubs.

The script does no type inference. Instead, the user supplies *patterns* in
a configuration file. The script matches these patterns to:


   The names of arguments in functions and methods and

   The text of *return expressions*. Return expressions are the actual text
   of whatever follows the "return" keyword. The script removes all comments
   in return expressions and converts all strings to "str". This preprocessing
   greatly simplifies pattern matching.

For example, given the method:

def foo(self, i, s):
    if i:
        return "abc" # a comment
        return s

and the patterns:

i: int
s: str

the script produces the stub:

def foo(i: int, s: str) --> str: ...

Edward K. Ream
March 31, 2016
Edward K. Ream: edreamleo at Leo:

More information about the Python-announce-list mailing list