The discussion of asserts got me thinking about Programming by Contract. Back 
in the 90s, I had occasion to learn Eiffel programming language. ( 
https://en.wikipedia.org/wiki/Eiffel_(programming_language) The concepts are 
intriguing, although Eiffel itself had barriers to widespread adoption.

Reviewing the topic, I found Wikipedia mentioned some Python implementations. I 
kicked the tires of “deal” and found it straightforward. I’m wondering if 
anyone on the list has experience using any of the Programming by Contract 
modules?

#!/usr/bin/env python3
import argparse
import deal

@deal.pre(lambda x: x > 7)
@deal.pre(lambda x: isinstance(x, int))
def func(x):
    print(x)


parser = 
argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--nodeal', action='store_true', help="Disable deal")
parser.add_argument('bad_choice', choices=('type', 'value'))
args = parser.parse_args()
if args.nodeal:
    deal.disable()
func(8)
if args.bad_choice == 'type':
    func("8")
if args.bad_choice == 'value':
    func(1)
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to