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 27 (modified by malte.appeltauer, 11 years ago) (diff)




Python 2.6
ContextPy on PyPy

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.


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.

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


This list contains our publications related to the ContextPy. The documents provided on this site are included by the contributing authors as a means to ensure timely dissemination of scholarly and technical work on a non-commercial basis. Copyright and all rights therein are maintained by the authors or by other copyright holders, notwithstanding that they have offered their works here electronically. It is understood that all persons copying this information will adhere to the terms and constraints invoked by each author's copyright. These works may not be reposted without the explicit permission of the copyright holder.

  • Robert Hirschfeld, Michael Perscheid, Christian Schubert, and Malte Appeltauer.
    Dynamic Contract Layers.
    In Proceedings of the ACM Symposium on Applied Computing (SAC) 2010, pages 2169-2175, Sierre, Switzerland, March 22-26, 2010, ACM Press.
    pdf, bibtex

© ACM, 2010. This is the authors' version of the work. It is posted here by permission of ACM for your personal use. Not for redistribution. The definitive version will be published in proceedings of the ACM Symposium on Applied Computing.


Attachments (1)

Download all attachments as: .zip