Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: flake8-abp/flake8_abp.py

Issue 29345337: Noissue - Fix edge cases with raw strings in flake8-abp (Closed)
Patch Set: Added test Created May 30, 2016, 10:17 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | flake8-abp/tests/A110.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: flake8-abp/flake8_abp.py
===================================================================
--- a/flake8-abp/flake8_abp.py
+++ b/flake8-abp/flake8_abp.py
@@ -384,33 +384,32 @@
continue
if kind == tokenize.STRING:
- match = re.search(r'^(u)?(b)?(r)?((""")?.*)$',
+ match = re.search(r'^([rub]*)([\'"]{1,3})(.*)\2$',
token, re.IGNORECASE | re.DOTALL)
- (is_unicode, is_bytes, is_raw,
- literal, has_doc_quotes) = match.groups()
+ prefixes, quote, text = match.groups()
+ prefixes = prefixes.lower()
if first_token and re.search(r'^(?:(?:def|class)\s|$)',
previous_logical):
- if not has_doc_quotes:
+ if quote != '"""':
yield (start, 'A109 use triple double '
'quotes for docstrings')
- elif is_unicode or is_bytes or is_raw:
+ elif prefixes:
yield (start, "A109 don't use u'', b'' "
"or r'' for doc strings")
elif start[0] == end[0]:
Sebastian Noack 2016/05/30 12:33:41 I just realized, after pushing this change, that w
- if is_raw:
- literal = re.sub(r'\\(?!{})'.format(literal[0]),
- '\\\\\\\\', literal)
+ if 'r' in prefixes:
+ if quote != "'" and not (quote == '"' and "'" in text):
+ yield (start, 'A110 use single quotes for raw string')
+ else:
+ prefix = 'b' if sys.version_info[0] >= 3 else 'u'
+ if prefix not in prefixes:
+ prefix = ''
- if sys.version_info[0] >= 3:
- if is_bytes:
- literal = 'b' + literal
- elif is_unicode:
- literal = 'u' + literal
-
- if ascii(eval(literal)) != literal:
- yield (start, "A110 string literal doesn't match "
- '{}()'.format(ascii.__name__))
+ literal = '{0}{1}{2}{1}'.format(prefix, quote, text)
+ if ascii(eval(literal)) != literal:
+ yield (start, "A110 string literal doesn't match "
+ '{}()'.format(ascii.__name__))
first_token = False
« no previous file with comments | « no previous file | flake8-abp/tests/A110.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld