On Mon, Aug 5, 2019 at 2:24 PM <raymond.hettinger@gmail.com> wrote:
For Python 3.8, the DeprecationWarning was converted to a SyntaxWarning which is visible by default. The intention is to make it a SyntaxError in Python 3.9.
This once seemed like a reasonable and innocuous idea to me; however, I've been using the 3.8 beta heavily for a month and no longer think it is a good idea. The warning crops up frequently, often due to third-party packages (such as docutils and bottle) that users can't easily do anything about. And during live demos and student workshops, it is especially distracting.
Those third-party packages will need to be fixed in time for 3.9. This isn't the first time this has happened.
I now think our cure is worse than the disease. If code currently has a non-raw string with '\latex', do we really need Python to yelp about it (for 3.8) or reject it entirely (for 3.9)? If someone can't remember exactly which special characters need to be escaped, do we really need to stop them in their tracks during a data analysis session? Do we really need to reject ASCII art in docstrings: ` \-------> special case'?
IIRC, the original problem to be solved was false positives rather than false negatives: filename = '..\training\new_memo.doc'. The warnings and errors don't do (and likely can't do) anything about this.
Many MANY file names will include some that are and some that aren't. If you're lucky, it'll begin "C:\Users" and you'll get an immediate hard error; but if it starts out "C:\Program Files", this warning is what's going to catch it. (Still true in lowercase for both of those.)
If Python 3.8 goes out as-is, we may be punching our users in the nose and getting almost no gain from it. ISTM this is a job best left for linters. For a very long time, Python has been accepting the likes of 'more \latex markup' and has been silently converting it to 'more \\latex markup'. I now think it should remain that way. This issue in the 3.8 beta releases has been an almost daily annoyance for me and my customers. Depending on how you use Python, this may not affect you or it may arise multiple times per day.
P.S. Before responding, it would be a useful exercise to think for a moment about whether you remember exactly which characters must be escaped or whether you habitually put in an extra backslash when you aren't sure. Then see: https://bugs.python.org/issue32912
With alphabetics, I never put in an extra backslash just to be sure. My habit is to escape the quotation mark used to delimit the string, the escape character itself, and nothing else, unless I'm actually constructing a deliberate escape sequence. Except in a regular expression, and then I'm inevitably bitten by differences between grep, sed, Python, etc, etc, etc, so I have to just test it anyway. What does Python actually gain by allowing errors to pass silently? Are there any other languages that allow arbitrary backslash sequences through unchanged? I tested Lua (syntax error), Pike (syntax warning), GCC in both C and C++ (warning), and Node.js (silent). Incidentally, I haven't found any other language in which "asdf\qwer" == "asdf\\qwer"; they're always just ignoring the backslash altogether. IMO Python's solution is better, but Lua's is best. A bad escape is an error. ChrisA