Unexpected behaviour with DeprecationWarning, Python 3.7 and escape codes

Peter pacqa100 at yahoo.com.au
Thu Aug 23 06:08:00 EDT 2018


I understand that Python 3.7 now issues DeprecationWarning for code 
entered in the interactive shell and also for single-module programs. I 
see this behaviour with:

C:\wrk> python
python 3.7.0 (v3.7.0:...
>>> import imp
__main__:1: DeprecationWarning: the imp module is deprecated...

But if I use an unknown escape code, then the expected warning doesn't 
issue:

>>> print('Hello \world')
Hello \world

But if I explicitly turn on default warnings, then I do get it:

C:\wrk> python -Wd
>>> print('Hello \world')
<stdin>:1: DeprecationWarning: invalid escape sequence \w
Hello \world


Shouldn't I see the "invalid escape sequence" deprecation warning under 
3.7 without having to turn on default warnings? They are both warnings 
of class DeprecationWarning. Am I not seeing something? Is this a bug?

I suspect it might have something to do with /when/ the warning is 
evaluated (parsing time vs runtime), but I'm not sure, and I'm not sure 
if that should be relevant to whether the warning is in fact raised. (I 
am aware of PEP 565)

Running CPython 3.7.0 on Windows 10, standard

Thanks for your insights.

Peter





More information about the Python-list mailing list