[Python-bugs-list] [ python-Bugs-585915 ] assert return values
noreply@sourceforge.net
noreply@sourceforge.net
Wed, 24 Jul 2002 06:28:42 -0700
Bugs item #585915, was opened at 2002-07-24 13:28
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=585915&group_id=5470
Category: Python Interpreter Core
Group: Feature Request
Status: Open
Resolution: None
Priority: 5
Submitted By: Thomas Leonard (tal197)
Assigned to: Nobody/Anonymous (nobody)
Summary: assert return values
Initial Comment:
It would be nice to write:
def root(x):
assert x >= 0
assert return >= 0
...
or
def get_path(foo):
if foo is None: return None
assert return is not None
...
and have the 'return' assertion checked when the function
exits. 'return' is already a reserved keyword so the
syntax doesn't introduce any incompatibility.
This might make functions more self-documenting, since
asserts at the end / in the middle tend to get lost.
Even if the assert goes at the end, it's still clearer, eg:
def foo():
...
assert min <= return <= max
return bar(min, max)
vs
def foo():
...
tmp = bar(min, max)
assert min <= tmp <= max
return tmp
Thanks!
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=585915&group_id=5470