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

v4: Use raw-string notation for regex to avoid invalid escape sequence #727

Merged
merged 1 commit into from
Oct 30, 2018

Conversation

hugovk
Copy link
Contributor

@hugovk hugovk commented Oct 30, 2018

Same as #698 but for the v4 branch.

Closes #698

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 30, 2018
@codecov
Copy link

codecov bot commented Oct 30, 2018

Codecov Report

Merging #727 into v4 will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##               v4     #727   +/-   ##
=======================================
  Coverage   84.54%   84.54%           
=======================================
  Files          36       36           
  Lines         977      977           
  Branches      108      108           
=======================================
  Hits          826      826           
  Misses         93       93           
  Partials       58       58
Impacted Files Coverage Δ
sendgrid/helpers/mail/validators.py 44.44% <100%> (ø) ⬆️

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 f04267b...28b7402. Read the comment docs.

@thinkingserious thinkingserious added type: community enhancement feature request not on Twilio's roadmap hacktoberfest difficulty: easy fix is easy in difficulty status: ready for deploy code ready to be released in next deploy and removed status: code review request requesting a community code review or review from Twilio labels Oct 30, 2018
@thinkingserious
Copy link
Contributor

Hello @hugovk,

Thanks again for the PR!

It's HACKTOBERFEST! We want to show our appreciation by sending you some special Hacktoberfest swag. If you have not already, could you please fill out this form so we can send it to you? Thanks!

Team SendGrid DX

@thinkingserious thinkingserious merged commit 33536e8 into sendgrid:v4 Oct 30, 2018
@hugovk hugovk deleted the patch-1 branch October 31, 2018 06:46
@thinkingserious
Copy link
Contributor

Hello @hugovk,

Thanks again for the PR!

You have earned 34 out of the 5 points needed to receive glorious SendGrid Hacktoberfest swag.

Please take a moment to checkout this link to find more issues to get you past the required threshold or to simply continue the celebration.

Also, please be sure you have officially registered with us here by November 1, 2018 to qualify.

If you have any questions you can email us at [email protected].

Thank you and Happy Hacktobering!

Team SendGrid

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: ready for deploy code ready to be released in next deploy type: community enhancement feature request not on Twilio's roadmap
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants