From 7064ecf3fb1144e9bc83cd0968fc4b77102341d9 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 12 Jul 2018 08:53:48 +0200 Subject: [PATCH] Don't use invalid escape sequences in regex, see https://github.com/davidhalter/jedi-vim/issues/843 --- parso/python/pep8.py | 6 +++--- parso/python/tree.py | 2 +- parso/utils.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/parso/python/pep8.py b/parso/python/pep8.py index 59fe452..2a037f9 100644 --- a/parso/python/pep8.py +++ b/parso/python/pep8.py @@ -391,11 +391,11 @@ class PEP8Normalizer(ErrorFinder): if value.lstrip('#'): self.add_issue(part, 266, "Too many leading '#' for block comment.") elif self._on_newline: - if not re.match('#:? ', value) and not value == '#' \ + if not re.match(r'#:? ', value) and not value == '#' \ and not (value.startswith('#!') and part.start_pos == (1, 0)): self.add_issue(part, 265, "Block comment should start with '# '") else: - if not re.match('#:? [^ ]', value): + if not re.match(r'#:? [^ ]', value): self.add_issue(part, 262, "Inline comment should start with '# '") self._reset_newlines(spacing, leaf, is_comment=True) @@ -677,7 +677,7 @@ class PEP8Normalizer(ErrorFinder): elif typ == 'string': # Checking multiline strings for i, line in enumerate(leaf.value.splitlines()[1:]): - indentation = re.match('[ \t]*', line).group(0) + indentation = re.match(r'[ \t]*', line).group(0) start_pos = leaf.line + i, len(indentation) # TODO check multiline indentation. elif typ == 'endmarker': diff --git a/parso/python/tree.py b/parso/python/tree.py index 294ddfe..24d0caa 100644 --- a/parso/python/tree.py +++ b/parso/python/tree.py @@ -252,7 +252,7 @@ class String(Literal): @property def string_prefix(self): - return re.match('\w*(?=[\'"])', self.value).group(0) + return re.match(r'\w*(?=[\'"])', self.value).group(0) def _get_payload(self): match = re.search( diff --git a/parso/utils.py b/parso/utils.py index a4801b9..8b9fb16 100644 --- a/parso/utils.py +++ b/parso/utils.py @@ -45,7 +45,7 @@ def split_lines(string, keepends=False): lst.append('') return lst else: - return re.split('\n|\r\n', string) + return re.split(r'\n|\r\n', string) def python_bytes_to_unicode(source, encoding='utf-8', errors='strict'):