any chance for contracts and invariants in Python?

Ian Kelly ian.g.kelly at gmail.com
Thu Feb 14 19:05:46 CET 2013


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
code.



More information about the Python-list mailing list