[Python-ideas] PEP 8: raw strings & regular expressions
M.-A. Lemburg
mal at egenix.com
Thu Oct 22 04:32:43 EDT 2015
On 22.10.2015 04:44, Ben Finney wrote:
> Yury Selivanov <yselivanov.ml at gmail.com>
> writes:
>
>> I was a little bit frustrated that Sublime Text and Atom didn't
>> support all Python 3 features (mainly annotations & async/await
>> syntax), so I decided to write a new highlighter:
>
> Thanks for scratching your itch and releasing the result as free software!
>
>> In the process, we had to make a decision on how to highlight raw
>> string literals -- r''. Many existing highlighters assume that all raw
>> strings are regexps, and highlight them as such, i.e. '\s' and '\n'
>> will be highlighted.
>
> That is evidently a simple mistake. Merely knowing that a token is a raw
> string does not justify the assumption that the string is a regular
> expression, or a filesystem entry name, or a line in a network protocol,
> or anything except plain text.
>
> Perhaps some more explicit context could be used to signal what the
> intent of a raw string is, but you'd need to find a strong consensus
> that programmers actually intend that. “It's a raw string” doesn't
> justify any of those assumptions.
>
>> I think that it might be a good idea to state the following in PEP 8:
>
> No, I don't think the mistaken assumptions you've described should be
> enshrined in a style guide. Instead, the mistaken assumptions should be
> changed.
Agreed. Highlighters should follow language definitions,
not the other way around ;-)
Yuri: Perhaps you could make the behavior optional in your
highlighter and allow people to turn off the highlighting
as regular expression, if they find they don't like the
highlighting.
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Experts (#1, Oct 22 2015)
>>> Python Projects, Coaching and Consulting ... http://www.egenix.com/
>>> Python Database Interfaces ... http://products.egenix.com/
>>> Plone/Zope Database Interfaces ... http://zope.egenix.com/
________________________________________________________________________
::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
More information about the Python-ideas
mailing list