[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Unexpected behaviour with DeprecationWarning, Python 3.7 and escape codes

On 2018-08-23 06:08 AM, Peter via Python-list wrote:
> 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...

Valid warning.

> 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

I don't know why it issues DeprecationWarning but this is not the same
as the previous line.  In this case \w is invalid and, as far as I know,
 has always been invalid.  I think it should be a different warning but
I do understand why it is in a different code path in Python.

It doesn't issue any warning in 2.7 by the way.  It still prints the
same thing so it is still an invalid escape sequence.

D'Arcy J.M. Cain
Vybe Networks Inc.
IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com