Merge ~smoser/curtin:cleanup/fix-tip-pycodestyle-invalid-escape-sequences into curtin:master
Status: | Merged |
---|---|
Approved by: | Scott Moser |
Approved revision: | f9f227789776c1b0975c9f1675e72a4a3663b130 |
Merge reported by: | Scott Moser |
Merged at revision: | 2ee52452fa5f3be088aa50b7d3609d5818c1524d |
Proposed branch: | ~smoser/curtin:cleanup/fix-tip-pycodestyle-invalid-escape-sequences |
Merge into: | curtin:master |
Diff against target: |
73 lines (+7/-8) 4 files modified
curtin/block/mdadm.py (+3/-4) curtin/commands/curthooks.py (+1/-1) tests/vmtests/__init__.py (+1/-1) tests/vmtests/test_pollinate_useragent.py (+2/-2) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Scott Moser (community) | Approve | ||
Chad Smith | Approve | ||
Server Team CI bot | continuous-integration | Approve | |
Review via email: mp+343012@code.launchpad.net |
Commit message
pycodestyle: Fix invalid escape sequences in string literals.
A bit of information from python doc that I got by never having known:
String literals may optionally be prefixed with a letter `r' or `R';
such strings are called raw strings and use different rules for
backslash escape sequences.
...
Unless an `r' or `R' prefix is present, escape sequences in strings are
interpreted according to rules similar to those used by Standard C.
So basically, any use of \ not followed by one of [\'"abfnrtv]
or \ooo (octal) \xhh (hex) or a newline is invalid. This is most
commonly seen for us in regex. To solve, you either:
a.) use a raw string r'...'
b.) correctly escape the \ that was not intended to be interpreted.
Python has deprecated these invalid string literals now
https:/
and pycodestyle is identifying them with a W605 warning.
https:/
IIRC, if we want to use \ escapes, then the string must be a raw string. There are few cases where you drop the r'' and others were you add it.
At least for regex, I think we can consistently use r'', and for other causes (we pass strings to a shell) we've escaped things like $; those, IIRC, don't need escaping unless we're running them through shell.