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 bskinn
Recipients brett.cannon, bskinn, takluyver, xtreak
Date 2019-04-23.19:30:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1556047824.27.0.888013341474.issue36695@roundup.psfhosted.org>
In-reply-to
Content
It looks to me like it's a standard feature of the CPython string rendering routines, where if single and double quotes are present in any string, the preferred rendering is enclosure with single quotes with escaped internal single quotes.

On 3.6.6, regardless how I enter the following, it always returns enclosed in single quotes:

>>> """ ' " """
' \' " '

>>> ''' ' " '''
' \' " '

>>> ' \' " '
' \' " '

>>> " ' \" "
' \' " '

For my particular situation, then, the problem is that my warning message, as it sits in the source, consists of a double-quoted string that contains single quotes.  Then, when 3.8 doctest goes to print the source line, it has to print a string containing both single and double quotes, so the above default rendering rule kicks in and it gets printed with enclosing single-quotes. For 3.7 doctest, where the regex doesn't match, the source line doesn't get printed, and so the resulting string contains no double quotes, and thus the string gets printed with enclosing double quotes.

Clearly, the solution is just for me to change the warning message! And indeed, changing to `warnings.warn("foo has no bar")` and updating the expected result to `'...UserWarning: foo has no bar\n...'` yields a passing test on both 3.7 and 3.8 now.
History
Date User Action Args
2019-04-23 19:30:24bskinnsetrecipients: + bskinn, brett.cannon, takluyver, xtreak
2019-04-23 19:30:24bskinnsetmessageid: <1556047824.27.0.888013341474.issue36695@roundup.psfhosted.org>
2019-04-23 19:30:24bskinnlinkissue36695 messages
2019-04-23 19:30:24bskinncreate