Context-aware return

Steven D'Aprano steve at pearwood.info
Wed Sep 16 22:31:32 EDT 2015


On Sun, 13 Sep 2015 09:27 am, Ned Batchelder wrote:

> On Thursday, September 10, 2015 at 8:44:01 PM UTC-4, Denis McMahon wrote:
>> On Fri, 11 Sep 2015 03:54:14 +1000, Steven D'Aprano wrote:
>> 
>> > If I did this thing, would people follow me down the street booing and
>> > jeering and throwing things at me?
>> 
>> Yes
>> 
>> >>> x = func()
>> >>> x
>> >>> func()
>> >>> print x == func()
>> >>> assert x == func()
>> 
>> Would you expect the last two calls to func() to return 999 or "Awesome"?
>> Why? What is the material difference if any between interpreter (a)
>> displaying the return value and (b) comparing the return value with
>> another value.
>> 
>> Debugging nightmare!
> 
> I'll add my voice to the rising chorus condemning the very notion
> of a function that behaves this way!
> 
> Then, I'll give you an implementation (Python 2):

Excellent! *cough* I mean, well, that's interesting. Of course no sane
developer would ever use such a thing.

Thanks to everyone who tried to discourage me from using this.




-- 
Steven




More information about the Python-list mailing list