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
Issue #1081: non necessary raw strings #1178
Conversation
Wow! @Mema5, @Gwin73 thanks! I will review this shortly. Offtop: can you please share your story behind this feature? Do you practice pair programming? Or is it a part of some kind of practice? And the most important question for me as a maintainer: why did you choose this project to contribute to? You rock! 👾 🚀 |
Thank you, it is rewarding to receive such a positive feedback :) Actually we are a group of 5 students (@fward @Gwin73 @Fils2 @ruwaid123 @Mema5) and we contribute as part of a course assignment. So yes, it is mostly to learn and gain experience on software engineering practices! The project will only last one week, but we are glad if it is useful! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your work! 👍
There are several minor things to polish and I will schedule this PR for 0.15
release.
tests/test_visitors/test_tokenize/test_primitives/test_string_tokens/test_string_modifier.py
Outdated
Show resolved
Hide resolved
modifiers, string_def = split_prefixes(token) | ||
|
||
if 'r' in modifiers.lower(): | ||
if '\\' not in string_def.encode('unicode-escape').decode(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r'\'
is better here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please also explain encode('unicode-escape').decode()
part? Why is it required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, r'\'
is not correct in Python I think.
Python 3.6.9
>>> a=r'\'
File "<stdin>", line 1
a=r'\'
^
SyntaxError: EOL while scanning string literal
>>>
The encode('unicode-escape').decode()
is a workaround to convert into a raw string. (see here). If you know something more beautiful let me know!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, about r'\'
part 👍
Can you please test your code without encode('unicode-escape').decode()
? Will it still work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mema5 have you tried running tests without encode('unicode-escape').decode()
? Did it work?
* CHANGELOG.md: new header for release 0.15.0 * added contribution * Related to PR wemake-services#1178
modifiers, string_def = split_prefixes(token) | ||
|
||
if 'r' in modifiers.lower(): | ||
if '\\' not in string_def.encode('unicode-escape').decode(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mema5 have you tried running tests without encode('unicode-escape').decode()
? Did it work?
…e '\' character. If there is no '\' in the string a raw string should not be used. Closes issue #8 Relates to issue#1081 on the original repository
…edViolation (WPS357). Follows the general structure for documentation. Relates to original issue wemake-services#1081. Closes #11
…some cases to make the test pass. Related to issue #9
* CHANGELOG.md: new header for release 0.15.0 * added contribution * Related to PR wemake-services#1178
@Mema5 can you please rebase your branch? |
@sobolevn here it is! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost done! The last round of review.
There are just 3 minor notes and we are ready to go.
Thank you!
Pull Request Test Coverage Report for Build 2656
💛 - Coveralls |
Pull Request Test Coverage Report for Build 2664
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot! Your work will be merged into 0.15
Codecov Report
@@ Coverage Diff @@
## master #1178 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 105 105
Lines 5531 5540 +9
Branches 1224 1226 +2
=========================================
+ Hits 5531 5540 +9
Continue to review full report at Codecov.
|
First PR for our group
@fwald and I solved this issue today. We added the new rule along with tests and documentation. We also refactored old tests and enforced the new rule in the project.
Thank you for your answers!
Checklist
CHANGELOG.md
Related issues
🙏 Please, if you or your company is finding wemake-python-styleguide valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/wemake-python-styleguide. As a thank you, your profile/company logo will be added to our main README which receives hundreds of unique visitors per day.