STINNER Victor added the comment:

> Maybe the compiler should emit a warning to say that the code doesn't make 
> sense at all and is ignored?

Oh ok, now I recall a similar issue that I posted 3 years ago: issue #17516, 
"Dead code should be removed".

Example of suspicious code:

def func():
   func2(),

func() calls func2() and then create a tuple of 1 item with the func2() result. 
See my changeset 33bdd0a985b9 for examples in the Python source code. The 
parser or compiler should maybe help to developer to catch such strange code :-)

In some cases, the code really contains code explicitly dead:

def test_func():
   return
   do_real_stuff()

do_real_stuff() is never called. Maybe it was a deliberate choice, maybe it was 
a mistake in a very old code base, bug introduced after multiple refactoring, 
and high turn over in a team? Again, we should emit a warning on such case?

Hum, these warnings have a larger scope than this specific issue (don't emit 
LOAD_CONST for constants in expressions).

See also the related thread on python-dev for the specific case of triple 
quoted strings ("""string"""): 
https://mail.python.org/pipermail/python-dev/2013-March/124925.html

It was admitted that it's a convenient way to insert a comment and it must not 
emit a warning (at least, not by default?)

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26204>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to