Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #84437
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.012 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'pycon': 0.01; 'static': 0.04; 'subject:Python': 0.06; 'pypy': 0.07; 'iterate': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'jan': 0.12; '24,': 0.16; 'ast': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'int):': 0.16; 'types,': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'module,': 0.24; 'parse': 0.24; 'fairly': 0.24; 'cc:2**0': 0.24; 'header:In-Reply- To:1': 0.27; 'raise': 0.29; 'message-id:@mail.gmail.com': 0.30; 'clever': 0.31; "d'aprano": 0.31; 'really,': 0.31; 'steven': 0.31; 'types.': 0.31; 'themselves': 0.32; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'too': 0.37; 'clear': 0.37; 'checks': 0.38; 'requiring': 0.38; 'pm,': 0.38; 'skip:b 40': 0.39; 'skip:o 30': 0.61; 'skip:n 10': 0.64; 'more': 0.64; 'different': 0.65; 'worth': 0.66; 'analysis': 0.75; '2015': 0.84; '4:29': 0.84; 'subject:Solution': 0.84; 'subject:Proposal': 0.91; 'this;': 0.91; 'watched': 0.91; 'to:none': 0.92 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=J0Alm3rUAJRHmqGDeDJa0PDqNUtCdIxVtPusSHJODqc=; b=HrRl3THin71czPnJx20mUS5mCMMO2nlXmbPqfEH6eGKmuYf2pj0txudP3lXy7ohcYG jgF/qxuoilRNdeOguYXBiQ/3F/MwV7zQlv+wPvEehR4lcBbDNuqRCCkbMuRwEuuucXGc 4dVOT68KfhRYnBBaX7IusPXdIMj7Bign0bHBrdgiAAet5n/sY/qqf5uoy3l7ABkxAQJD +WDhtnwnt3YOUMAdNZJGrfSy67ZKNbYIhEIM26zfDQqoo/RsF6BMKpal7P7ZRr7v8TEz 0gfrDqGPGmr+k7sPAuoqPtOQH2xhPKh6cBDHUMqWHIEKaIN9/NHZWEsoQbgOIdkRNNeC cflg== |
| MIME-Version | 1.0 |
| X-Received | by 10.224.128.196 with SMTP id l4mr21921493qas.100.1422077929013; Fri, 23 Jan 2015 21:38:49 -0800 (PST) |
| In-Reply-To | <54c32dae$0$13000$c3e8da3$5496439d@news.astraweb.com> |
| References | <6da1eb58-a0bb-4d37-8293-0a8cafe6a89c@googlegroups.com> <m9sep8$p53$1@ger.gmane.org> <mailman.18017.1421985858.18130.python-list@python.org> <5afad59b-5e8c-4821-85cf-9e971c8c7be6@googlegroups.com> <MPG.2f2cd54cf9ff377e98968a@nntp.aioe.org> <4b3b498a-c9b0-443d-8514-87ccd8e98f43@googlegroups.com> <MPG.2f2cecb4624e49c498968c@nntp.aioe.org> <MPG.2f2ced6df496308698968d@nntp.aioe.org> <87sif1dpgy.fsf@elektro.pacujo.net> <54c32dae$0$13000$c3e8da3$5496439d@news.astraweb.com> |
| Date | Sat, 24 Jan 2015 16:38:48 +1100 |
| Subject | Re: Python Sanity Proposal: Type Hinting Solution |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.18074.1422077931.18130.python-list@python.org> (permalink) |
| Lines | 29 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1422077931 news.xs4all.nl 2921 [2001:888:2000:d::a6]:59553 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:84437 |
Show key headers only | View raw
On Sat, Jan 24, 2015 at 4:29 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> Sufficiently clever type-checkers may use assertions to infer types, but
> requiring this is a non-starter.
Or they could use the isinstance checks themselves to infer types.
def func(arg):
if not isinstance(arg, int): raise ValueError("Expected an integer")
It's fairly straight-forward to do an AST parse on a module, iterate
over it for functions, and then look for a specific pattern like the
above:
If(test=UnaryOp(op=Not(), operand=Call(func=Name(id='isinstance',
ctx=Load()), args=[Name(id='arg', ctx=Load()), Name(id='int',
ctx=Load())], keywords=[], starargs=None, kwargs=None)),
body=[Raise(exc=Call(func=Name(id='ValueError', ctx=Load()),
args=[Str(s='Expected an integer')], keywords=[], starargs=None,
kwargs=None), cause=None)], orelse=[])
... okay, that's not exactly pretty, but it's still a straight-forward
structure. But having just watched a PyCon talk about PyPy and RPython
and type inference, it's pretty clear that static analysis can do a
*lot* more than this; so really, looking for isinstance checks is both
too hard and too simplistic to be really worth doing. Type hinting is
a different beast.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python Sanity Proposal: Type Hinting Solution Rick Johnson <rantingrickjohnson@gmail.com> - 2015-01-22 17:15 -0800
Re: Python Sanity Proposal: Type Hinting Solution MRAB <python@mrabarnett.plus.com> - 2015-01-23 03:22 +0000
Re: Python Sanity Proposal: Type Hinting Solution Terry Reedy <tjreedy@udel.edu> - 2015-01-22 22:22 -0500
Re: Python Sanity Proposal: Type Hinting Solution Rick Johnson <rantingrickjohnson@gmail.com> - 2015-01-23 11:23 -0800
Re: Python Sanity Proposal: Type Hinting Solution Christian Gollwitzer <auriocus@gmx.de> - 2015-01-24 22:14 +0100
Re: Python Sanity Proposal: Type Hinting Solution Rustom Mody <rustompmody@gmail.com> - 2015-01-22 19:23 -0800
Re: Python Sanity Proposal: Type Hinting Solution Rick Johnson <rantingrickjohnson@gmail.com> - 2015-01-23 11:36 -0800
Re: Python Sanity Proposal: Type Hinting Solution Chris Angelico <rosuav@gmail.com> - 2015-01-23 14:59 +1100
Re: Python Sanity Proposal: Type Hinting Solution Rick Johnson <rantingrickjohnson@gmail.com> - 2015-01-23 11:48 -0800
Re: Python Sanity Proposal: Type Hinting Solution Chris Angelico <rosuav@gmail.com> - 2015-01-24 06:59 +1100
Re: Python Sanity Proposal: Type Hinting Solution Rick Johnson <rantingrickjohnson@gmail.com> - 2015-01-23 12:59 -0800
Re: Python Sanity Proposal: Type Hinting Solution Mario Figueiredo <marfig@gmail.com> - 2015-01-23 22:02 +0100
Re: Python Sanity Proposal: Type Hinting Solution Rick Johnson <rantingrickjohnson@gmail.com> - 2015-01-23 13:59 -0800
Re: Python Sanity Proposal: Type Hinting Solution Mario Figueiredo <marfig@gmail.com> - 2015-01-23 23:42 +0100
Re: Python Sanity Proposal: Type Hinting Solution Mario Figueiredo <marfig@gmail.com> - 2015-01-23 23:45 +0100
Re: Python Sanity Proposal: Type Hinting Solution sohcahtoa82@gmail.com - 2015-01-23 14:52 -0800
Re: Python Sanity Proposal: Type Hinting Solution Mario Figueiredo <marfig@gmail.com> - 2015-01-24 00:14 +0100
Re: Python Sanity Proposal: Type Hinting Solution Marko Rauhamaa <marko@pacujo.net> - 2015-01-24 01:52 +0200
Re: Python Sanity Proposal: Type Hinting Solution Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-24 16:29 +1100
Re: Python Sanity Proposal: Type Hinting Solution Chris Angelico <rosuav@gmail.com> - 2015-01-24 16:38 +1100
Re: Python Sanity Proposal: Type Hinting Solution Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-24 17:36 +1100
Re: Python Sanity Proposal: Type Hinting Solution Chris Angelico <rosuav@gmail.com> - 2015-01-24 17:47 +1100
Re: Python Sanity Proposal: Type Hinting Solution Marko Rauhamaa <marko@pacujo.net> - 2015-01-24 11:27 +0200
Re: Python Sanity Proposal: Type Hinting Solution Rick Johnson <rantingrickjohnson@gmail.com> - 2015-01-23 15:39 -0800
Re: Python Sanity Proposal: Type Hinting Solution Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-25 00:29 +1100
Re: Python Sanity Proposal: Type Hinting Solution Mario Figueiredo <marfig@gmail.com> - 2015-01-24 15:09 +0100
Re: Python Sanity Proposal: Type Hinting Solution Mario Figueiredo <marfig@gmail.com> - 2015-01-24 15:32 +0100
Re: Python Sanity Proposal: Type Hinting Solution Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-25 03:05 +1100
Re: Python Sanity Proposal: Type Hinting Solution Marco Buttu <marco.buttu@gmail.com> - 2015-01-24 15:25 +0100
Re: Python Sanity Proposal: Type Hinting Solution Rick Johnson <rantingrickjohnson@gmail.com> - 2015-01-24 08:41 -0800
Re: Python Sanity Proposal: Type Hinting Solution Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-25 04:26 +1100
Re: Python Sanity Proposal: Type Hinting Solution Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-01-24 17:36 +0000
Re: Python Sanity Proposal: Type Hinting Solution Paul Rubin <no.email@nospam.invalid> - 2015-01-24 09:37 -0800
Re: Python Sanity Proposal: Type Hinting Solution Chris Angelico <rosuav@gmail.com> - 2015-01-25 06:59 +1100
Re: Python Sanity Proposal: Type Hinting Solution Terry Reedy <tjreedy@udel.edu> - 2015-01-23 00:03 -0500
Re: Python Sanity Proposal: Type Hinting Solution Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-23 16:59 +1100
Re: Python Sanity Proposal: Type Hinting Solution "Fetchinson ." <fetchinson@googlemail.com> - 2015-01-23 14:23 +0100
Re: Python Sanity Proposal: Type Hinting Solution Rick Johnson <rantingrickjohnson@gmail.com> - 2015-01-23 12:21 -0800
Re: Python Sanity Proposal: Type Hinting Solution Mario Figueiredo <marfig@gmail.com> - 2015-01-23 22:12 +0100
Re: Python Sanity Proposal: Type Hinting Solution Rick Johnson <rantingrickjohnson@gmail.com> - 2015-01-23 14:26 -0800
Re: Python Sanity Proposal: Type Hinting Solution Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-24 17:21 +1100
Re: Python Sanity Proposal: Type Hinting Solution Tim Chase <python.list@tim.thechases.com> - 2015-01-24 06:47 -0600
Re: Python Sanity Proposal: Type Hinting Solution Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-25 00:40 +1100
Re: Python Sanity Proposal: Type Hinting Solution Roy Smith <roy@panix.com> - 2015-01-24 09:06 -0500
Re: Python Sanity Proposal: Type Hinting Solution "Fetchinson ." <fetchinson@googlemail.com> - 2015-01-24 22:01 +0100
Re: Python Sanity Proposal: Type Hinting Solution Chris Angelico <rosuav@gmail.com> - 2015-01-24 04:11 +1100
Re: Python Sanity Proposal: Type Hinting Solution "Fetchinson ." <fetchinson@googlemail.com> - 2015-01-23 22:07 +0100
Re: Python Sanity Proposal: Type Hinting Solution Chris Angelico <rosuav@gmail.com> - 2015-01-23 16:31 +1100
csiph-web