From 037f696d26ca88fa9740a6b38b6ca1af44c912f6 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sun, 1 Jul 2018 18:05:24 -0400 Subject: [PATCH] Enable pycodestyle W605 (invalid escape sequence). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The only changes visible at the AST level, checked using https://github.com/asottile/astpretty, are zerver/lib/test_fixtures.py: '\x1b\\[(1|0)m' ↦ '\\x1b\\[(1|0)m' '\\[[X| ]\\] (\\d+_.+)\n' ↦ '\\[[X| ]\\] (\\d+_.+)\\n' which is fine because re treats '\\x1b' and '\\n' the same way as '\x1b' and '\n'. Signed-off-by: Anders Kaseorg --- scripts/lib/process-mobile-i18n | 2 +- tools/check-urls | 4 +- .../spiders/check_documentation.py | 2 +- tools/get-handlebar-vars | 4 +- tools/js-dep-visualizer.py | 6 +- tools/lib/find_add_class.py | 2 +- tools/linter_lib/custom_check.py | 116 +++++++++--------- tools/linter_lib/pep8.py | 2 +- zerver/lib/actions.py | 4 +- zerver/lib/bugdown/__init__.py | 2 +- zerver/lib/emoji.py | 2 +- zerver/lib/notifications.py | 2 +- zerver/lib/push_notifications.py | 2 +- zerver/lib/subdomains.py | 4 +- zerver/lib/test_classes.py | 2 +- zerver/lib/test_fixtures.py | 6 +- zerver/lib/tex.py | 2 +- zerver/lib/upload.py | 8 +- zerver/management/commands/compilemessages.py | 4 +- zerver/management/commands/makemessages.py | 16 +-- zerver/models.py | 2 +- zerver/tests/test_home.py | 2 +- zerver/tests/test_management_commands.py | 2 +- zerver/tests/test_middleware.py | 2 +- zerver/tests/test_narrow.py | 4 +- zerver/tests/test_notifications.py | 2 +- zerver/tests/test_realm_filters.py | 8 +- zerver/tests/test_signup.py | 8 +- zerver/tests/test_slack_importer.py | 8 +- zerver/tests/test_templates.py | 2 +- zerver/tests/test_upload.py | 2 +- zerver/views/messages.py | 2 +- zerver/webhooks/appfollow/view.py | 2 +- zerver/webhooks/github_legacy/view.py | 2 +- zerver/webhooks/jira/view.py | 4 +- .../commands/add_mock_conversation.py | 2 +- 36 files changed, 123 insertions(+), 123 deletions(-) diff --git a/scripts/lib/process-mobile-i18n b/scripts/lib/process-mobile-i18n index ba72d52a3b..8d6a5885b9 100755 --- a/scripts/lib/process-mobile-i18n +++ b/scripts/lib/process-mobile-i18n @@ -11,7 +11,7 @@ def get_json_filename(locale: str) -> str: def get_locales() -> List[str]: tracked_files = check_output(['git', 'ls-files', 'static/locale']) tracked_files = tracked_files.decode().split() - regex = re.compile('static/locale/(\w+)/LC_MESSAGES/django.po') + regex = re.compile(r'static/locale/(\w+)/LC_MESSAGES/django.po') locales = ['en'] for tracked_file in tracked_files: matched = regex.search(tracked_file) diff --git a/tools/check-urls b/tools/check-urls index 9625651e5c..23d82447bf 100755 --- a/tools/check-urls +++ b/tools/check-urls @@ -12,8 +12,8 @@ def check_urls(): 'analytics/urls.py', 'zilencer/urls.py'] - pattern_1 = "\s+\[?url\(.+,\s*'.+'\s*,\s*.*\)" - pattern_2 = '\s+\[?url\(.+,\s*".+"\s*,\s*.*\)' + pattern_1 = r"\s+\[?url\(.+,\s*'.+'\s*,\s*.*\)" + pattern_2 = r'\s+\[?url\(.+,\s*".+"\s*,\s*.*\)' for url_file in url_files: with open(url_file) as f: diff --git a/tools/documentation_crawler/documentation_crawler/spiders/check_documentation.py b/tools/documentation_crawler/documentation_crawler/spiders/check_documentation.py index 1977c359ca..534e56cfc7 100755 --- a/tools/documentation_crawler/documentation_crawler/spiders/check_documentation.py +++ b/tools/documentation_crawler/documentation_crawler/spiders/check_documentation.py @@ -19,5 +19,5 @@ def get_start_url() -> List[str]: class DocumentationSpider(BaseDocumentationSpider): name = "documentation_crawler" deny_domains = ['localhost:9991'] - deny = ['\_sources\/.*\.txt'] + deny = [r'\_sources\/.*\.txt'] start_urls = get_start_url() diff --git a/tools/get-handlebar-vars b/tools/get-handlebar-vars index f7faefb236..f4a049dc19 100755 --- a/tools/get-handlebar-vars +++ b/tools/get-handlebar-vars @@ -16,14 +16,14 @@ def debug(obj): def parse_file(fn): # type: (str) -> Dict[str, Any] text = open(fn).read() - tags = re.findall('{+\s*(.*?)\s*}+', text) + tags = re.findall(r'{+\s*(.*?)\s*}+', text) root = {} # type: Dict[str, Any] context = root stack = [] # type: List[Dict[str, Any]] def set_var(var, val): # type: (str, Any) -> None - num_levels_up = len(re.findall('\.\.', var)) + num_levels_up = len(re.findall(r'\.\.', var)) if num_levels_up: var = var.split('/')[-1] stack[-1 * num_levels_up][var] = val diff --git a/tools/js-dep-visualizer.py b/tools/js-dep-visualizer.py index 886bbfb180..4e8a7088fd 100755 --- a/tools/js-dep-visualizer.py +++ b/tools/js-dep-visualizer.py @@ -44,11 +44,11 @@ def get_js_edges(): modules.append(dict( name=name, path=path, - regex=re.compile('[^_]{}\.\w+\('.format(name)) + regex=re.compile(r'[^_]{}\.\w+\('.format(name)) )) - comment_regex = re.compile('\s+//') - call_regex = re.compile('[^_](\w+\.\w+)\(') + comment_regex = re.compile(r'\s+//') + call_regex = re.compile(r'[^_](\w+\.\w+)\(') methods = defaultdict(list) # type: DefaultDict[Edge, List[Method]] edges = set() diff --git a/tools/lib/find_add_class.py b/tools/lib/find_add_class.py index e652f2113d..028ef6ac1b 100644 --- a/tools/lib/find_add_class.py +++ b/tools/lib/find_add_class.py @@ -81,7 +81,7 @@ def find(fns): for i, line in enumerate(lines): if 'addClass' in line: html_classes = [] # type: List[str] - m = re.search('addClass\([\'"](.*?)[\'"]', line) + m = re.search(r'''addClass\(['"](.*?)['"]''', line) if m: html_classes = [m.group(1)] if not html_classes: diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.py index 33ad30e7e1..61252844a0 100644 --- a/tools/linter_lib/custom_check.py +++ b/tools/linter_lib/custom_check.py @@ -97,10 +97,10 @@ def custom_check_file(fn, identifier, rules, color, skip_rules=None, max_length= if (max_length is not None and line_length > max_length and '# type' not in line and 'test' not in fn and 'example' not in fn and # Don't throw errors for markdown format URLs - not re.search("^\[[ A-Za-z0-9_:,&()-]*\]: http.*", line) and + not re.search(r"^\[[ A-Za-z0-9_:,&()-]*\]: http.*", line) and # Don't throw errors for URLs in code comments - not re.search("[#].*http.*", line) and - not re.search("`\{\{ api_url \}\}[^`]+`", line) and + not re.search(r"[#].*http.*", line) and + not re.search(r"`\{\{ api_url \}\}[^`]+`", line) and "# ignorelongline" not in line and 'migrations' not in fn): print("Line too long (%s) at %s line %s: %s" % (len(line), fn, i+1, line_newline_stripped)) failed = True @@ -138,7 +138,7 @@ def build_custom_checkers(by_lang): # 'exclude_line': 'set([(, ), ...])' - excludes all lines matching in the file from linting. # 'include_only': 'set([, ...])' - includes only those files where is a substring of the filepath. trailing_whitespace_rule = { - 'pattern': '\s+$', + 'pattern': r'\s+$', 'strip': '\n', 'description': 'Fix trailing whitespace' } @@ -160,11 +160,11 @@ def build_custom_checkers(by_lang): 'good_lines': ['foo(1, 2, 3)', 'foo = bar # some inline comment'], 'bad_lines': ['foo(1, 2, 3)', 'foo(1, 2, 3)']}, ] # type: RuleList - markdown_whitespace_rules = list([rule for rule in whitespace_rules if rule['pattern'] != '\s+$']) + [ + markdown_whitespace_rules = list([rule for rule in whitespace_rules if rule['pattern'] != r'\s+$']) + [ # Two spaces trailing a line with other content is okay--it's a markdown line break. # This rule finds one space trailing a non-space, three or more trailing spaces, and # spaces on an empty line. - {'pattern': '((?]([gG]ithub)[^\.\-\_\"\<]', # exclude usage in hrefs/divs + {'pattern': r'''[^\/\-\."'\_\=\>]([gG]ithub)[^\.\-\_"\<]''', # exclude usage in hrefs/divs 'description': "github should be spelled GitHub"}, {'pattern': '[oO]rganisation', # exclude usage in hrefs/divs 'description': "Organization is spelled with a z", @@ -603,7 +603,7 @@ def build_custom_checkers(by_lang): 'description': "Use Botserver instead of botserver or bot server."}, ]) + comma_whitespace_rule html_rules = whitespace_rules + prose_style_rules + [ - {'pattern': 'placeholder="[^{#](?:(?!\.com).)+$', + {'pattern': r'placeholder="[^{#](?:(?!\.com).)+$', 'description': "`placeholder` value should be translatable.", 'exclude_line': [('templates/zerver/register.html', 'placeholder="acme"'), ('templates/zerver/register.html', 'placeholder="Acme or Aκμή"')], @@ -630,21 +630,21 @@ def build_custom_checkers(by_lang): 'description': "`title` value should be translatable.", 'good_lines': [''], 'bad_lines': ["

"]}, - {'pattern': 'title="[^{\:]', + {'pattern': r'title="[^{\:]', 'exclude_line': set([ ('templates/zerver/app/markdown_help.html', ':heart:') ]), 'exclude': set(["templates/zerver/emails"]), 'description': "`title` value should be translatable."}, - {'pattern': '\Walt=["\'][^{"\']', + {'pattern': r'''\Walt=["'][^{"']''', 'description': "alt argument should be enclosed by _() or it should be an empty string.", 'exclude': set(['static/templates/settings/display-settings.handlebars', 'templates/zerver/app/keyboard_shortcuts.html', 'templates/zerver/app/markdown_help.html']), 'good_lines': ['{{ _(name) }}', ''], 'bad_lines': ['Foo Image']}, - {'pattern': '\Walt=["\']{{ ?["\']', + {'pattern': r'''\Walt=["']{{ ?["']''', 'description': "alt argument should be enclosed by _().", 'good_lines': ['{{ _(name) }}'], 'bad_lines': ['{{ ']}, @@ -721,11 +721,11 @@ def build_custom_checkers(by_lang): 'description': "Do not use inline