Validating Function Arguments in Python Signal Processing Applications20 Sep 2016
We had a presentation at the 2016 Scientific Computing with Python (SciPy) conference on validation of function arguments in Python. This is an attempt at advancing correctness of results by providing an intuitive function argument validation scheme for Python signal processing applications. An accompanying paper has now been published in the conference proceedings. SciPy 2016 was held in Austin, Texas, USA, July 11 - 17, 2016.
Python does not have a built-in mechanism to validate the value of function arguments. This can lead to nonsensical exceptions, unexpected behaviour, erroneous results and the like. In the present paper, we define the concept of so-called application-driven data types which place a layer of abstraction on top of Python data types. With this concept in mind, we discuss the current argument validation solutions of PyDBC, Traitlets and Numtraits, MyPy, PyValid, and PyContracts. We find that they share the issue of expressing the validation scheme in terms of Python objects rather than in terms of the data they hold. Consequently, we lay out a suggestion for a validation strategy including what qualifies as a validation scheme, how to create an interface which promotes both usability and readability, and which Python constructs to encourage using for validation encapsulation. A reference implementation of the suggested validation strategy is part of the open-source Python package, Magni which is thus presented along with a number of examples of the usages of this package.
- The original paper is available open access (CC-BY) here, URL: http://conference.scipy.org/proceedings/scipy2016/patrick_pedersen.html
- The reference implementation is part of the Magni Python software package which can be downloaded here, DOI: 10.5278/VBN/MISC/Magni
- Supplementary material is available here, URL: https://github.com/SIP-AAU/SciPy2016_material