Brian Skinn <bsk...@alum.mit.edu> added the comment:

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.

----------

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

Reply via email to