Greg Darke <da...@google.com> added the comment:

I would argue that there is none (especially if it is tuple/something that is 
always true) -- thus why I would assume that Python would provide a warning.

This bug comes from a discussion I was having with someone earlier today where 
they mentioned that it would be nice if the linter complained about the 
following::

  assert 'not reachable'

That code is incorrect (the assertion will never fire, due to the string 
evaluating to True). We remembered that python did complain about tuples, and 
tried to see what the warning looked like using a trivial example::

  assert(False, 'msg')

We noticed that this code did not produce a warning on python3.8, but did 
produce a warning on python2.7.

After much digging we found that the following did work on python3.8::

  assert(False, str())

This allowed us to deduce that something special was happening with constants 
(well, it also required us to look at the disassembly of the ops codes for the 
above two statements).

Going back to your original question, I have used `assert False` in code to 
"test" if a piece of code was being reached. I have also used it for things 
similar to the piece of code that started all of this::

  if some_expression:
    # ...
  elif some_other_expression:
    #...
  else:
    assert False, 'This code is unreachable'

----------

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

Reply via email to