f



ANN: make_stub_files 0.1

m
=E2=80=8Bake_stub_files.py =E2=80=8B
0.1 is now available here <https://github.com/edreamleo/make-stub-files>.

This script eliminates much of the drudgery of creating python stub (.pyi)
<https://www.python.org/dev/peps/pep-0484/#stub-files> 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
<https://github.com/JukkaL/mypy/blob/master/mypy/stubgen.py> 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:

   1.

   The names of arguments in functions and methods and
   2.

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

For example, given the method:

def foo(self, i, s):
    if i:
        return "abc" # a comment
    else:
        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@gmail.com Leo: http://leoeditor.com/
---------------------------------------------------------------------------=
---------------
0
Edward
3/31/2016 11:31:54 AM
comp.lang.python.announce 7374 articles. 0 followers. Post Follow

0 Replies
371 Views

Similar Articles

[PageSpeed] 38

Reply: