Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!news2.euro.net!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.027 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'subject:Python': 0.05; 'definitions': 0.07; 'purpose.': 0.07; 'definition,': 0.09; 'expectation': 0.09; 'inherited': 0.09; 'subclasses': 0.09; 'ignore': 0.13; 'hierarchy': 0.16; 'traverse': 0.16; 'wrote:': 0.17; 'thu,': 0.17; 'feb': 0.19; 'code.': 0.20; 'work,': 0.22; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'message- id:@mail.gmail.com': 0.27; 'class': 0.29; 'classes': 0.30; 'call.': 0.30; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'requiring': 0.35; 'received:209.85.220': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'method': 0.36; 'should': 0.36; 'option': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'enable': 0.60; 'first': 0.61; 'production': 0.63; 'respect': 0.63; 'choose': 0.65; 'special': 0.73; '2013': 0.84; 'original.': 0.84; 'subject:any': 0.84; 'to:name:python': 0.84; 'contracts': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:content-type; bh=bNs2kBVA64UHgfjR3HUbVQZHaXkS5hWZeHTqUTe3sXA=; b=sHn21AVByR9jiV6/2+YhnbLgSLFi+kyt3njWHP7Q27W2jELV76esX+xMgyizrj2x6M 5nGaf2FCzLqSkeOLwNPBIo2oK4iSA5Is31yEcDIDlto3Q1JdScTRuTeZAjNA01aCasf9 //cNXU7NZs+dcDRHQR2E+qYzYcuNGpZx/WASmAMAxMuo2hZX8a66sSvCnP9voKTa2/o+ xBqEd7Buxocn9o0CsUOMLM/JcAFratsQYaMAbP5zWkQiPpnAjjEGUQMIAh4YwIBpusov g/0wkRzstzR2eLmwlrTSLz98Jea4N1bze13PvR1Wq6mz56A7JH881QseKqglB2AP3IPf FjHA== X-Received: by 10.66.47.193 with SMTP id f1mr510908pan.48.1360865186968; Thu, 14 Feb 2013 10:06:26 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <511D18C8.5040404@phihag.de> References: <70c4a8a5-0e8d-4e5c-b0cd-e4ccd90c5cb3@googlegroups.com> <511D18C8.5040404@phihag.de> From: Ian Kelly Date: Thu, 14 Feb 2013 11:05:46 -0700 Subject: Re: any chance for contracts and invariants in Python? To: Python Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list 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: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1360865190 news.xs4all.nl 6927 [2001:888:2000:d::a6]:39717 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38872 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.