Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT: use raw strings for regular expressions #469

Merged
merged 1 commit into from
Mar 25, 2020

Conversation

tacaswell
Copy link
Contributor

Description of proposed changes

In Python strings '' is the escape to enter some special
characters (ex '\n' for new line and '\t' for tab). Previously
if '' was not followed by a letter that made one of the escape
sequences Python would shrug and assume you really meant just '',
however this leads to lots of silent errors (when you type \m instead
of \n or tau needs to be written \tau) so now Python is warning and
in the future will fail if there is an invalid escape sequence. By
making thees strings 'raw' (the r prefix) it tells Python to never
treat '' in that string as the start of an escape sequence.

What is the goal of this pull request? What does this pull request change?

Testing

This should have no behavior change in released version of Python, will have less warnings in py36+ and is future proofed against (I think) py39 when these will become syntax errors.

It would be best to set your test suite to fail on warnings, but that will require fixing a number of your dependencies (ex neherlab/treetime#108) and finding a way to suppress the warning from Bio.Alphabet.

Thank you for contributing to Nextstrain!

In Python strings '\' is the escape to enter some special
characters (ex '\n' for new line and '\t' for tab).  Previously
if '\' was not followed by a letter that made one of the escape
sequences Python would shrug and assume you really meant just '\',
however this leads to lots of silent errors (when you type \m instead
of \n or tau needs to be written \\tau) so now Python is warning and
in the future will fail if there is an invalid escape sequence.  By
making thees strings 'raw' (the r prefix) it tells Python to never
treat '\' in that string as the start of an escape sequence.
@tacaswell
Copy link
Contributor Author

only took 3 tries...

Copy link

@Zsailer Zsailer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks, @tacaswell!

@huddlej huddlej merged commit 2ddb1b9 into nextstrain:master Mar 25, 2020
@tacaswell tacaswell deleted the mnt_escape_re_patterns branch March 25, 2020 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants