On 04Aug2019 2122, raymond.hettinger@gmail.com wrote:
We should revisit what we want to do (if anything) about invalid escape sequences.
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.
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.
I broadly agree that the warning is very annoying, particularly when it comes from third-party packages (I see it from some of pip's vendored dependencies all the time), though I do also see many people bitten by FileNotFoundError because of a '\n' in their filename. Raymond - a question if I may. How often do you see these occurring from docstrings, compared to regular strings? I feel like I only ever see the irrelevant warnings being raised from docstrings, so if others confirm this perhaps there's a way we could suppress the warnings where the string is the entire expression? Cheers, Steve