Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python.announce > #2092

ANN: make_stub_files 0.1

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From "Edward K. Ream" <edreamleo@gmail.com>
Newsgroups comp.lang.python.announce
Subject ANN: make_stub_files 0.1
Date Thu, 31 Mar 2016 06:31:54 -0500
Lines 61
Approved python-announce-list@python.org
Message-ID <mailman.249.1459424106.28225.python-announce-list@python.org> (permalink)
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de vRsSmlD72E+hacBCuM+BdAZmd6mGrgMzi6ZeDXZzLLiw==
Return-Path <edreamleo@gmail.com>
X-Original-To python-announce-list@python.org
Delivered-To python-announce-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'patterns': 0.04; 'removes': 0.05; 'converts': 0.07; 'expressions': 0.07; 'matches': 0.07; 'subject:ANN': 0.07; '0.1': 0.09; 'edward': 0.09; 'effect.': 0.09; 'method:': 0.09; 'overwrite': 0.09; 'str)': 0.09; 'subject:0.1': 0.09; 'subject:skip:m 10': 0.09; 'tune': 0.09; 'url:github': 0.09; 'python': 0.10; '<>.': 0.11; 'files.': 0.13; 'output': 0.13; 'def': 0.13; '2016': 0.16; 'expressions.': 0.16; 'keyword.': 0.16; 'matching.': 0.16; 'options)': 0.16; 'ream': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'simplifies': 0.16; 'stub': 0.16; 'url:py': 0.16; 'creates': 0.18; '2.x': 0.22; '31,': 0.22; 'arguments': 0.22; 'int,': 0.22; 'produces': 0.22; 'file.': 0.22; 'script': 0.25; 'command': 0.26; 'message- id:@mail.gmail.com': 0.27; 'developing': 0.28; 'actual': 0.28; '(it': 0.29; 'command-line': 0.29; 'follows': 0.29; 'str': 0.29; 'url:peps': 0.29; 'allows': 0.30; 'comments': 0.30; 'creating': 0.30; 'code': 0.30; 'option': 0.31; 'source': 0.33; 'url:python': 0.33; 'instead,': 0.33; 'int': 0.33; 'file': 0.34; 'received:google.com': 0.35; 'text': 0.35; 'url:dev': 0.35; 'comment': 0.35; 'but': 0.36; 'should': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'skip:& 10': 0.37; 'received:209': 0.38; 'names': 0.38; 'files': 0.38; 'whatever': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'email addr:gmail.com': 0.62; 'here.': 0.62; 'providing': 0.62; 'more': 0.63; 'march': 0.64; 'here': 0.66; 'iterative': 0.84; 'received :mail-yw0-f170.google.com': 0.84; 'url:master': 0.84; 'yours': 0.89; 'eliminates': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to; bh=B5U5vGgxhXsFEi13FAoQTrur3CXsVV0p0teZogsPluw=; b=DHUFPPlXfymh2p2lSj8C5D7i9CRbOO3ypkbpL7eK6yDjXpb+X+mlfX6ZKUSYlA8h/3 YiNKRAUo1jPNZCSUwK5BjYY5JoNIX7DtLxKpJdNKuTFgbys81Jn5Pc7ssUqubXlxtmg6 HXIV86fdMlyChLvOj0ZqkIgVQAzeyJzQS30DY2sRjDg0GONgVyPwvteWTVDzZrEWR3DN 1GFFwFzAP8P1lFg/1Xj7qDqmjmON2cstHYex3a2Se6R8csnDroMgeEGsyzK/8QPh88vH vajJh+aL6Vh31MIB/tqBr/wWvG96S51tJ2VmzJmbugS07IWh+FAn6A89eL53i9gl25Hl 3iXA==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to; bh=B5U5vGgxhXsFEi13FAoQTrur3CXsVV0p0teZogsPluw=; b=HhH9FOEVO4bA178yg4A1BW86EI6585F7sRr9L44JNjmL0U1MJ+WgG4uG9W/yB6+0ar txqtp/5tSvKxwSFbOL6B+vmO7PRexabN3vm1WI3/4slw0xf3dyaJXaS1/j31V7fDP9yU /lIIAJjnlQ02y/MjDfJTU+wh13rW4cIEzu2ptVbeHsOdKVa10r2pD261ezQpaME5TvZT 8HCSo+HrKVbIkkhNI7+M8xfo0RMUZW3BaB6aNc5KDJlYEv5FbOx/PI4I/PmFN8mfJG7j N4Xhj9ibQ8n5iwiZHMcVnr43OJou5Wj1tLwr71zB5OgLyJhAyZ/ohdUXwROPO/ZoGtcA eitQ==
X-Gm-Message-State AD7BkJLH7nDHqQRxA9c+ZNoBq7uCymlMxXFkqZS9hHx/udhGhAR1hm1XjEMbYsWpY8lmj18WL/RXz+4US5d3HQ==
X-Received by 10.129.115.3 with SMTP id o3mr7860017ywc.285.1459423914294; Thu, 31 Mar 2016 04:31:54 -0700 (PDT)
X-Mailman-Approved-At Thu, 31 Mar 2016 07:35:05 -0400
X-Content-Filtered-By Mailman/MimeDel 2.1.21
X-BeenThere python-announce-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id Announcement-only list for the Python programming language <python-announce-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-announce-list>, <mailto:python-announce-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-announce-list/>
List-Post <mailto:python-announce-list@python.org>
List-Help <mailto:python-announce-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-announce-list>, <mailto:python-announce-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python.announce:2092

Show key headers only | View raw


m
​ake_stub_files.py ​
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 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
    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/
------------------------------------------------------------------------------------------

Back to comp.lang.python.announce | Previous | Next | Find similar | Unroll thread


Thread

ANN: make_stub_files 0.1 "Edward K. Ream" <edreamleo@gmail.com> - 2016-03-31 06:31 -0500

csiph-web