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


Groups > comp.lang.python > #38874

Re: any chance for contracts and invariants in Python?

Date 2013-02-14 18:18 +0000
From MRAB <python@mrabarnett.plus.com>
Subject Re: any chance for contracts and invariants in Python?
References <70c4a8a5-0e8d-4e5c-b0cd-e4ccd90c5cb3@googlegroups.com> <511D18C8.5040404@phihag.de> <CALwzidnDuqCMOdpmM2doD9EkL6JyOvDsqBZ+xzzMb-pXgD+Hng@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1774.1360865934.2939.python-list@python.org> (permalink)

Show all headers | View raw


On 2013-02-14 18:05, Ian Kelly wrote:
> On Thu, Feb 14, 2013 at 10:03 AM, Philipp Hagemeister <phihag@phihag.de> 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.

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


Thread

any chance for contracts and invariants in Python? mrkafk@gmail.com - 2013-02-14 03:42 -0800
  Re: any chance for contracts and invariants in Python? Philipp Hagemeister <phihag@phihag.de> - 2013-02-14 18:03 +0100
  Re: any chance for contracts and invariants in Python? Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-14 11:05 -0700
  Re: any chance for contracts and invariants in Python? MRAB <python@mrabarnett.plus.com> - 2013-02-14 18:18 +0000
  Re: any chance for contracts and invariants in Python? Ethan Furman <ethan@stoneleaf.us> - 2013-02-14 10:33 -0800
  Re: any chance for contracts and invariants in Python? Mark Janssen <dreamingforward@gmail.com> - 2013-02-14 18:33 -0800

csiph-web