Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.03; 'syntax': 0.03; 'anyway.': 0.04; 'subject:Python': 0.05; 'context': 0.05; 'motivated': 0.05; 'preference': 0.05; 'reject': 0.05; 'ascii': 0.07; 'character,': 0.07; 'compile-time': 0.07; 'escape': 0.07; 'newline': 0.07; 'plenty': 0.07; 'prefix': 0.07; 'raised': 0.07; 'sequences.': 0.07; 'python': 0.09; '(although': 0.09; 'backslash': 0.09; 'differently.': 0.09; 'literal': 0.09; "wouldn't": 0.11; '"\\\'"': 0.16; '"escape': 0.16; 'confusion': 0.16; 'discussion.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'head,': 0.16; 'kinds,': 0.16; 'literals,': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'subject:ideas': 0.16; 'syntax.': 0.16; 'string': 0.17; 'wrote:': 0.17; 'requests': 0.18; 'subject:] ': 0.19; 'causing': 0.20; 'followed': 0.20; 'bit': 0.21; 'error.': 0.21; 'not,': 0.21; 'exceptions': 0.22; 'greg': 0.22; 'seems': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '(which': 0.26; 'guess': 0.27; 'prevent': 0.27; "doesn't": 0.28; 'fine': 0.28; 'arguments.': 0.29; 'character.': 0.29; "d'aprano": 0.29; 'extending': 0.29; 'received:192.168.1.3': 0.29; 'steven': 0.29; 'case,': 0.29; 'character': 0.29; 'probably': 0.29; 'error': 0.30; 'sense': 0.31; 'asking': 0.32; 'received:84': 0.32; 'null': 0.33; 'ones,': 0.33; 'to:addr:python-list': 0.33; '(with': 0.33; 'that,': 0.34; 'built-in': 0.35; 'exist': 0.35; 'sequence': 0.35; 'open': 0.35; 'sometimes': 0.35; 'something': 0.35; 'but': 0.36; 'characters': 0.36; 'should': 0.36; 'too': 0.36; 'enough': 0.36; 'correctly': 0.37; 'being': 0.37; 'some': 0.38; 'to:addr:python.org': 0.39; 'step': 0.39; 'received:192': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'subject:-': 0.40; 'end': 0.40; 'think': 0.40; 'future.': 0.62; 'helps': 0.63; 'header :Reply-To:1': 0.68; 'sounds': 0.71; 'reply-to:no real name:2**0': 0.72; 'special': 0.73; 'subject:have': 0.79; 'difference.': 0.84; 'escaping': 0.84; 'reply-to:addr:python.org': 0.84; 'subject:skip:S 10': 0.84; 'thing,': 0.84; 'doubling': 0.91; 'subject:\t': 0.91; 'subject:Make': 0.91; 'have.': 0.95 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=YaM/Fntf c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=AAvI7MrX_rgA:10 a=DR7gAP6Vkw4A:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=Qg3mNUxdcZ0A:10 a=EtKVO1T88cAtdRzE5dkA:9 a=wPNLvfGTeEIA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Thu, 11 Oct 2012 15:17:48 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: [Python-ideas] Make undefined escape sequences have SyntaxWarnings References: <20121010214607.354902d6@pitrou.net> <50760DED.2030801@pearwood.info> <507635D9.2040107@pearwood.info> <50765A68.9080607@canterbury.ac.nz> In-Reply-To: <50765A68.9080607@canterbury.ac.nz> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 54 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1349965073 news.xs4all.nl 6911 [2001:888:2000:d::a6]:34851 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:31120 On 2012-10-11 06:34, Greg Ewing wrote: > Steven D'Aprano wrote: >> If you escape a character, you should get >> something. If it's a special character, you get the special meaning. >> If it's not, escaping should be transparent: escaping something that >> doesn't need escaping is a null op > > I think that calling "\n", "\t" etc. "escape sequences" is a misnomer > that is causing confusion in this discussion. > > The term "escape" in this context means to prevent something from > having a special meaning that it would otherwise have. But the > backslash in these is being used to *give* a special meaning to > the following character. > > In Python string literals, the only true escape sequences associated > with the backslash are '\\', "\'" and '\"'. > > So the backslash is a bit schizophrenic -- sometimes it's an escape > character, sometimes it's a prefix that imparts a special meaning. > > This means that "\c" where c is not special in any way is somewhat > ambiguous. Are you redundantly escaping something that doesn't > need it, are you asking for a special meaning that doesn't exist > (which is probably a mistake), or do you just want a literal > backslash? > > Python guesses that you want a literal backslash. This seems to be > motivated by the desire to minimise the need for backslash doubling. > That sounds fine in theory, but I don't think it helps much in > practice. I for one don't trust myself to keep the entire set of > special characters in my head, including all the rarely-used ones, > so I end up doubling every backslash anyway. > > Given that, I wouldn't have minded at all if Python had refused > to guess in this case, and raised a compile-time error. That would > have left the way open for extending the set of special chars in > the future. > >> Adding a new escape sequence is almost as big a step as adding a new >> built-in or new syntax. I see that as a good thing, it discourages too >> many requests for new escape sequences. > > I don't see it makes much difference. We get plenty of requests for > new syntax of all kinds, and we seem to have enough sense to reject > them unless they're backed by extremely good arguments. There's no > reason requests for new special chars should be treated any differently. > My own preference is that a backslash followed by an ASCII letter or digit either has a special meaning currently (with a compile-time error if it's not correctly formed) or is reserved for future use (with a compile-time currently), and that a backslash followed by any other character (codepoint) is a literal (although they may some exceptions to that, such as a backslash followed by a newline being ignored).