Warning of missing side effects

"Martin v. Löwis" martin at v.loewis.de
Sat May 2 06:02:55 EDT 2009

> But I'm used to exploiting side effect, and sometimes forget this rule 
> in my own classes. IS THERE A WAY to have the following produce a 
> runtime error?
>    def f():
>       x = 5
>       # no return
>    y = f()

Typically, this will produce a runtime error fairly quickly,
namely when you *use* the (presumed) return value of f().
You would normally try to perform some computation with y,
or invoke methods on it - and then you see that it is None.

So while it is not possible to get an exception on the
assignment, you will usually get a runtime error sooner
or later (most of the time, sooner).

FWIW, pylint -e reports on your code

E:  5: Assigning to function call which doesn't return


More information about the Python-list mailing list