[Python-ideas] PEP 8: raw strings & regular expressions

Ben Finney ben+python at benfinney.id.au
Wed Oct 21 22:44:14 EDT 2015


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.

-- 
 \           “We have clumsy, sputtering, inefficient brains…. It is a |
  `\     *struggle* to be rational and objective, and failures are not |
_o__) evidence for an alternative reality.” —Paul Z. Myers, 2010-10-14 |
Ben Finney



More information about the Python-ideas mailing list