[Python-bugs-list] [ python-Bugs-585915 ] assert return values
noreply@sourceforge.net
noreply@sourceforge.net
Wed, 24 Jul 2002 08:06:46 -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: Closed
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!
----------------------------------------------------------------------
>Comment By: Jeremy Hylton (jhylton)
Date: 2002-07-24 15:06
Message:
Logged In: YES
user_id=31392
I don't think this is a great feature. It seems like
control flow via yield or return could easily be overlooked
if it's inside an assert statement.
Regardless of whether I like the idea, the SF bug tracker
isn't the right place to make this suggestion. The right
thing to do is write a PEP describing the feature in detail,
then come up with a patch to implement it. If that's too
much work, but you really like the idea, you could try to
drum up interest on comp.lang.python.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=585915&group_id=5470