| Index: flake8-abp/flake8_abp.py |
| =================================================================== |
| --- a/flake8-abp/flake8_abp.py |
| +++ b/flake8-abp/flake8_abp.py |
| @@ -39,17 +39,17 @@ |
| } |
| ESSENTIAL_BUILTINS = set(dir(builtins)) - {'apply', 'buffer', 'coerce', |
| 'intern', 'file'} |
| LEAVE_BLOCK = (ast.Return, ast.Raise, ast.Continue, ast.Break) |
| VOLATILE = object() |
| -IS_UNICODE_LITERALS = False |
| +is_unicode_literals = False |
| def evaluate(node): |
| try: |
| return eval(compile(ast.Expression(node), '', 'eval'), {}) |
| except Exception: |
| return VOLATILE |
| @@ -374,26 +374,27 @@ |
| 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 |
| - global IS_UNICODE_LITERALS |
| + global is_unicode_literals |
| - # --- check if this is beginning of file |
| + # check if this is beginning of file |
| if tokens[0][3][0] == 1: |
| - IS_UNICODE_LITERALS = False |
| + is_unicode_literals = False |
| - # --- check if in unicode_literals mode |
| + # check if in unicode_literals mode |
| token_strings = [t[1] for t in tokens] |
| if token_strings[:3] == ['from', '__future__', 'import']: |
| - IS_UNICODE_LITERALS = 'unicode_literals' in token_strings |
| + if 'unicode_literals' in token_strings: |
| + is_unicode_literals = True |
| for kind, token, start, end, _ in tokens: |
| if kind == tokenize.INDENT or kind == tokenize.DEDENT: |
| continue |
| if kind == tokenize.STRING: |
| match = re.search(r'^(u)?(b)?(r)?((""")?.*)$', |
| token, re.IGNORECASE | re.DOTALL) |
| @@ -407,23 +408,23 @@ |
| 'quotes for docstrings') |
| elif is_unicode or is_bytes or is_raw: |
| yield (start, "A109 don't use u'', b'' " |
| "or r'' for doc strings") |
| elif start[0] == end[0]: |
| if is_raw: |
| literal = re.sub(r'\\(?!{})'.format(literal[0]), |
| '\\\\\\\\', literal) |
| + if is_unicode and not is_unicode_literals: |
| + yield (start, 'A112 use "from __future__ import' |
| + 'unicode_literals" instead of ' |
| + 'prefixing literals with "u"') |
| if sys.version_info[0] >= 3: |
| if is_bytes: |
| literal = 'b' + literal |
| - elif is_unicode and not IS_UNICODE_LITERALS: |
| - yield(start, 'A112 use "from __future__ import"' |
| - 'unicode_literals instead of prefixing' |
| - 'literals with "u"') |
| elif not is_bytes: |
| literal = 'u' + literal |
| if ascii(eval(literal)) != literal: |
| yield (start, "A110 string literal doesn't match " |
| '{}()'.format(ascii.__name__)) |
| first_token = False |