[issue38706] What should the error message in the exception raised by assertTrue and assertFalse be?

Terry J. Reedy report at bugs.python.org
Wed Nov 6 06:48:14 EST 2019


Terry J. Reedy <tjreedy at udel.edu> added the comment:

I pretty strongly dislike 'truthy' and 'falsey'.  They look slangy and https://en.wiktionary.org/wiki/truthy gives the main meaning as 
  (US, colloquial) Only superficially true; ...

The computer language usage is credited to Javascript here and some other sites (with the same meaning as in Python).

To be a bit pedantic, the current failure message for assertTrue(x) appears to be f'{repr(x)} is not true'.

Exception messages are English phrases and sentences, not Python code, so 'is' in exception messages is always the English 'is', as in
  NameError: name 'true' is not defined
I do not see any ambiguity.  Somewhat ironically, the original suggestion 'False is not True', which should better be written '<x> is not True' *could* be misinterpreted as code.

'x does not evaluate to true' strikes me as wrong because in this context, the evaluation by calling bool(x) is to True or False, not 'true' or 'false'.

'assertTrue' is an abbreviation for something like 'assertBoolTrue(x)' or more properly, assert_bool(x)_is_True.  A correct failure message, correct both as English and Python, should be something like 'bool(x) is not True'.  I see 'x is not true' as an informal English equivalent of the full claim.  Perhaps this should be better explained somewhere in the doc.  I do not really see 'x is not a true value' as adding anything.

We don't usually change exception messages in bugfix releases unless the message is buggy, as in actively misleading.  I also think making a change would need discussion on pydev.

----------
nosy:  -eric.smith, vinay.sajip
versions: +Python 3.9 -Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38706>
_______________________________________


More information about the Python-bugs-list mailing list