any chance for contracts and invariants in Python?
ethan at stoneleaf.us
Thu Feb 14 19:33:14 CET 2013
On 02/14/2013 10:05 AM, Ian Kelly wrote:
> On Thu, Feb 14, 2013 at 10:03 AM, Philipp Hagemeister <phihag at 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
I was under the impression that the real power of contracts was when
they are /not/ turned off -- the errors we don't catch in development
are the serious ones. ;)
More information about the Python-list