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

master: Use raw-string notation for regex to avoid invalid escape sequence #698

Closed
wants to merge 1 commit into from

Conversation

hugovk
Copy link
Contributor

@hugovk hugovk commented Oct 20, 2018

Checklist

  • I have made a material change to the repo (functionality, testing, spelling, grammar)
  • I have read the [Contribution Guide] and my PR follows them.
  • I updated my branch with the master branch.
  • [n/a] I have added tests that prove my fix is effective or that my feature works
  • [n/a] I have added necessary documentation about the functionality in the appropriate .md file
  • [n/a] I have added in line documentation to the code I modified

Short description of what this PR does:

  • Use raw-string notation for regex to avoid invalid escape sequence

From the re docs:

Regular expressions use the backslash character ('\') to indicate special forms or to allow special characters to be used without invoking their special meaning. This collides with Python’s usage of the same character for the same purpose in string literals; for example, to match a literal backslash, one might have to write '\\\\' as the pattern string, because the regular expression must be \\, and each backslash must be expressed as \\ inside a regular Python string literal.

The solution is to use Python’s raw string notation for regular expression patterns; backslashes are not handled in any special way in a string literal prefixed with 'r'. So r"\n" is a two-character string containing '\' and 'n', while "\n" is a one-character string containing a newline. Usually patterns will be expressed in Python code using this raw string notation.

Before

$ pycodestyle | grep W605
./sendgrid/helpers/mail/validators.py:27:16: W605 invalid escape sequence '\.'
./sendgrid/helpers/mail/validators.py:27:30: W605 invalid escape sequence '\.'
$

After

$ pycodestyle | grep W605

Once merged, the exception from #654 should be removed:

https://github.com/sendgrid/sendgrid-python/pull/654/files#diff-354f30a63fb0907d4ad57269548329e3R35

@thinkingserious thinkingserious added the status: code review request requesting a community code review or review from Twilio label Oct 20, 2018
@codecov
Copy link

codecov bot commented Oct 20, 2018

Codecov Report

Merging #698 into master will decrease coverage by 0.27%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #698      +/-   ##
==========================================
- Coverage   85.04%   84.77%   -0.28%     
==========================================
  Files          35       35              
  Lines        1157     1156       -1     
  Branches      172      172              
==========================================
- Hits          984      980       -4     
  Misses         90       90              
- Partials       83       86       +3
Impacted Files Coverage Δ
sendgrid/helpers/mail/validators.py 44.44% <100%> (ø) ⬆️
sendgrid/helpers/mail/spam_check.py 88.46% <0%> (-7.7%) ⬇️
sendgrid/helpers/inbound/config.py 93.93% <0%> (-3.12%) ⬇️
sendgrid/helpers/mail/exceptions.py 66.66% <0%> (ø) ⬆️
sendgrid/helpers/inbound/send.py 93.75% <0%> (ø) ⬆️
sendgrid/helpers/mail/content.py 84.61% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 90cfbf2...37f0486. Read the comment docs.

@hugovk hugovk mentioned this pull request Oct 20, 2018
6 tasks
Copy link
Contributor

@misterdorm misterdorm left a comment

Choose a reason for hiding this comment

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

Would you please rebase this against the v4 branch? Otherwise, LGTM. Thanks!

@misterdorm misterdorm added status: work in progress Twilio or the community is in the process of implementing hacktoberfest difficulty: easy fix is easy in difficulty and removed status: code review request requesting a community code review or review from Twilio labels Oct 30, 2018
Copy link
Contributor

@misterdorm misterdorm left a comment

Choose a reason for hiding this comment

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

Rebase to v4.

@hugovk hugovk changed the base branch from master to v4 October 30, 2018 21:59
@hugovk hugovk changed the base branch from v4 to master October 30, 2018 22:00
@hugovk hugovk changed the title Use raw-string notation for regex to avoid invalid escape sequence master: Use raw-string notation for regex to avoid invalid escape sequence Oct 30, 2018
@hugovk
Copy link
Contributor Author

hugovk commented Oct 30, 2018

Please see #727 as a replacement on the v4 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: easy fix is easy in difficulty status: work in progress Twilio or the community is in the process of implementing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants