[ python-Feature Requests-1114404 ] All Statements Should Have Return Values (Syntax Proposal)

SourceForge.net noreply at sourceforge.net
Thu Feb 3 00:08:33 CET 2005


Feature Requests item #1114404, was opened at 2005-02-01 20:27
Message generated for change (Comment added) made by goodger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1114404&group_id=5470

Category: Python Interpreter Core
Group: None
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Lenny Domnitser (ldrhcp)
Assigned to: Nobody/Anonymous (nobody)
Summary: All Statements Should Have Return Values (Syntax Proposal)

Initial Comment:
Python should allow a return value for some statements
or blocks such as `print` or `def`. This should not
always happen, but could certainly be useful.

This can be used instead of lambdas when something more
complex is required (the `def` example.)

What seems to me to be the most natural syntax is to
simply wrap the statement in parentheses. For example:

>>> foo = (print 'bar')
bar
>>> foo
'bar'
>>> f = (def f(x):
    if x < 0:
        return -5
    return x ** 2 )

>>> f
<function f at 0x00A575B0>
>>> # A useful example:
>>> do_some_sort_of_logging( ( raise SomeSortOfError ) )

It will generally be obvious what should be returned,
but why not be more explicit? Here are some loose specs:

`def` would return the defined function.
`class` would return the defined class.
`print` would return the string representation of the
printed object.
`raise` will return the exception.
`import` returns the module or a tuple of modules.

This is not mean to be complete or a definitive syntax,
but I'd certainly like this discussed and something
along the lines of this proposal implemented.

----------------------------------------------------------------------

>Comment By: David Goodger (goodger)
Date: 2005-02-02 18:08

Message:
Logged In: YES 
user_id=7733

In Python, expressions return values.  Statements don't. 
That's fundamental to the language.

In any case, such a proposal is too broad to discuss here. 
If you'd like to proceed, please write a PEP.  See
http://www.python.org/peps/pep-0001.html for the procedure.

Better yet, please discuss it on comp.lang.python
(python-list at python.org) first.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1114404&group_id=5470


More information about the Python-bugs-list mailing list