This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author darke
Recipients darke, serhiy.storchaka
Date 2021-03-15.09:44:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1615801458.27.0.268060242648.issue43497@roundup.psfhosted.org>
In-reply-to
Content
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'
History
Date User Action Args
2021-03-15 09:44:18darkesetrecipients: + darke, serhiy.storchaka
2021-03-15 09:44:18darkesetmessageid: <1615801458.27.0.268060242648.issue43497@roundup.psfhosted.org>
2021-03-15 09:44:18darkelinkissue43497 messages
2021-03-15 09:44:17darkecreate