wiki:ContextPy
close Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Version 4 (modified by malte.appeltauer, 9 years ago) (diff)

--

ContextPy

Overview

ContextPy, our context-oriented extension to the Python language, provides a COP-based approach to design by contract (DBC). DBC is a programming technique to separate contract enforcement from application code. DBC provides information about the applicability of methods and helps to narrow down the search space in case of a software failure. However, most DBC implementations suffer from inflexibility: Contract enforcement can only be activated or deactivated at compile-time or start-up, contracts are checked globally and cannot be restricted in their scope such as to the current thread of execution, and contracts cannot be grouped according to the concerns they relate to.

ContextPy provides DCL for fine-grained and flexible contract management and extends DBC by a grouping mechanism for contracts, thread-local activation and deactivation of such groups, and selective contract enforcement at run-time.

PyDCL, our proof-of-concept implementation of DCL, is built onto of ContextPy

Implementation

ContextPy supports the layer-in-class approach and with that allows developers to define their partial methods within the scope of the actual classes these methods are contributing to. Similar to all other COP extensions so far, ContextPy provides both layers, partial methods, and dynamic scoping.

Layers
In ContextPy layers are represented by regular objects that provide the identities layers need to exhibit at run-time. Layer access has to be managed by the developers.

Layer Composition The representation of activated and deactivated layers is handled by two stacks—one for thread- specific and one for globally activated layers. Layers can be(de-)activated using Python’s with statement or by library methods for stack operations.

Partial Methods In Python, each class has its own dictionary that maps identifiers (keys) to objects (values). For instance, a method is stored with its name as key and the method object as value. We introduce a layered method descriptor that consists of all (partial) methods and a cache

Attachments (1)

Download all attachments as: .zip