Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.05; 'decorator': 0.07; 'definitions': 0.07; 'purpose.': 0.07; 'definition,': 0.09; 'expectation': 0.09; 'inherited': 0.09; 'subclasses': 0.09; 'wraps': 0.09; 'ignore': 0.13; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'hierarchy': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'traverse': 0.16; 'wrote:': 0.17; 'thu,': 0.17; 'creates': 0.18; 'feb': 0.19; 'code.': 0.20; 'work,': 0.22; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'am,': 0.27; 'functions.': 0.27; 'class': 0.29; 'maybe': 0.29; 'classes': 0.30; 'call.': 0.30; 'to:addr:python- list': 0.33; 'requiring': 0.35; 'subject:?': 0.35; 'something': 0.35; 'method': 0.36; 'should': 0.36; 'option': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'enable': 0.60; 'first': 0.61; 'production': 0.63; 'respect': 0.63; 'choose': 0.65; 'header :Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'special': 0.73; '2013': 0.84; 'original.': 0.84; 'reply-to:addr:python.org': 0.84; 'subject:any': 0.84; 'contracts': 0.91 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=XeZXOvF5 c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=Tv4_tr9OjFAA:10 a=7k_ktU75BzwA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=XFdiRGhafKMA:10 a=FjnWQqUj12Qi0WWZy08A:9 a=wPNLvfGTeEIA:10 a=T6rte8_hsbQA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Thu, 14 Feb 2013 18:18:53 +0000 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 MIME-Version: 1.0 To: python-list@python.org Subject: Re: any chance for contracts and invariants in Python? References: <70c4a8a5-0e8d-4e5c-b0cd-e4ccd90c5cb3@googlegroups.com> <511D18C8.5040404@phihag.de> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1360865934 news.xs4all.nl 6900 [2001:888:2000:d::a6]:48304 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38874 On 2013-02-14 18:05, Ian Kelly wrote: > On Thu, Feb 14, 2013 at 10:03 AM, Philipp Hagemeister wrote: >> So any implementation has to choose one of the following: >> >> 1. Ignore invariants and postconditions of inherited classes - defeats >> the purpose. >> 2. Only respect definitions in classes and methods in the original >> definition, which would be unpythonic >> 3. Only respect the "original" definitions, for some value of original. >> Simarily, this would break monkey patching. >> 4. Update all subclasses whenever something changes. >> 5. Traverse the entire class hierarchy for every method call. >> >> Which option should be picked? > > #5, with the expectation that like assertions the entire machinery > would be turned off when the -O flag is passed, or perhaps even > requiring a special flag to enable in the first place. Contracts and > invariants would only be used in development work, not in production > code. > Maybe what it needs is a decorator that parses the docstrings, creates functions to do the checks, and then wraps them around the functions.