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

Unified Diff: flake8-abp/flake8_abp.py

Issue 29342824: Issue 4044 - Added handling for __future__ unicode_literals import to check_quotes() (Closed)
Patch Set: Created May 19, 2016, 9:57 p.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_unicode_literals.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
@@ -372,21 +372,25 @@
return (0, 'A303 non-default file encoding')
check_non_default_encoding.name = 'abp-non-default-encoding'
check_non_default_encoding.version = __version__
def check_quotes(logical_line, tokens, previous_logical):
first_token = True
+ is_unicode_literals = False
Sebastian Noack 2016/05/20 00:04:34 While I didnt test this change yet I have a hard t
Vasily Kuznetsov 2016/05/20 08:46:24 Funnily enough, the test does pass in the first ve
for kind, token, start, end, _ in tokens:
if kind == tokenize.INDENT or kind == tokenize.DEDENT:
continue
+ if token is 'unicode_literals':
Sebastian Noack 2016/05/20 00:04:34 It's not as simple as that. Following examples wil
Jon Sonesen 2016/05/20 02:00:01 Yes I should be checking the logical line object w
+ is_unicode_literals = True
+
if kind == tokenize.STRING:
match = re.search(r'^(u)?(b)?(r)?((""")?.*)$',
token, re.IGNORECASE | re.DOTALL)
(is_unicode, is_bytes, is_raw,
literal, has_doc_quotes) = match.groups()
if first_token and re.search(r'^(?:(?:def|class)\s|$)',
previous_logical):
@@ -401,16 +405,18 @@
literal = re.sub(r'\\(?!{})'.format(literal[0]),
'\\\\\\\\', literal)
if sys.version_info[0] >= 3:
if is_bytes:
literal = 'b' + literal
elif is_unicode:
literal = 'u' + literal
+ elif not is_unicode_literals:
Sebastian Noack 2016/05/20 00:04:34 Just add it to the condition above using "or" rath
Jon Sonesen 2016/05/20 02:00:01 Will do.
+ literal = 'u' + literal
if ascii(eval(literal)) != literal:
yield (start, "A110 string literal doesn't match "
'{}()'.format(ascii.__name__))
first_token = False
check_quotes.name = 'abp-quotes'
« no previous file with comments | « no previous file | flake8-abp/tests/A110_unicode_literals.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld