From f17b6009eea69beb6b1d1e395c1283027a8f22e6 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Tue, 8 Jan 2019 21:32:27 -0500 Subject: [PATCH 1/2] FIX: Escape chars in re --- numpydoc/docscrape.py | 9 +++++---- numpydoc/docscrape_sphinx.py | 2 +- numpydoc/numpydoc.py | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/numpydoc/docscrape.py b/numpydoc/docscrape.py index c5d9b0ec..48c96642 100644 --- a/numpydoc/docscrape.py +++ b/numpydoc/docscrape.py @@ -320,7 +320,8 @@ def _parse_summary(self): while True: summary = self._doc.read_to_next_empty_line() summary_str = " ".join([s.strip() for s in summary]).strip() - if re.compile('^([\w., ]+=)?\s*[\w\.]+\(.*\)$').match(summary_str): + compiled = re.compile(r'^([\w., ]+=)?\s*[\w\.]+\(.*\)$') + if compiled.match(summary_str): self['Signature'] = summary_str if not self._is_at_section(): continue @@ -392,7 +393,7 @@ def _str_indent(self, doc, indent=4): def _str_signature(self): if self['Signature']: - return [self['Signature'].replace('*', '\*')] + [''] + return [self['Signature'].replace('*', r'\*')] + [''] else: return [''] @@ -524,7 +525,7 @@ def __init__(self, func, role='func', doc=None, config={}): else: argspec = inspect.getargspec(func) signature = inspect.formatargspec(*argspec) - signature = '%s%s' % (func_name, signature.replace('*', '\*')) + signature = '%s%s' % (func_name, signature.replace('*', r'\*')) except TypeError: signature = '%s()' % func_name self['Signature'] = signature @@ -541,7 +542,7 @@ def __str__(self): out = '' func, func_name = self.get_func() - signature = self['Signature'].replace('*', '\*') + signature = self['Signature'].replace('*', r'\*') roles = {'func': 'function', 'meth': 'method'} diff --git a/numpydoc/docscrape_sphinx.py b/numpydoc/docscrape_sphinx.py index 776cbe4f..032850a1 100644 --- a/numpydoc/docscrape_sphinx.py +++ b/numpydoc/docscrape_sphinx.py @@ -165,7 +165,7 @@ def _process_param(self, param, desc, fake_autosummary): param) if obj_doc: # Overwrite desc. Take summary logic of autosummary - desc = re.split('\n\s*\n', obj_doc.strip(), 1)[0] + desc = re.split(r'\n\s*\n', obj_doc.strip(), 1)[0] # XXX: Should this have DOTALL? # It does not in autosummary m = re.search(r"^([A-Z].*?\.)(?:\s|$)", diff --git a/numpydoc/numpydoc.py b/numpydoc/numpydoc.py index 763c022d..7056b6f8 100644 --- a/numpydoc/numpydoc.py +++ b/numpydoc/numpydoc.py @@ -50,7 +50,7 @@ def rename_references(app, what, name, obj, options, lines): references = set() for line in lines: line = line.strip() - m = re.match(sixu('^.. \\[(%s)\\]') % app.config.numpydoc_citation_re, + m = re.match(sixu(r'^.. \[(%s)\]') % app.config.numpydoc_citation_re, line, re.I) if m: references.add(m.group(1)) From 8e1a964e84f3cb4074e188eaf6b67c01ae3ebe6f Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Sat, 12 Jan 2019 00:04:01 -0500 Subject: [PATCH 2/2] FIX: Missed a few --- numpydoc/tests/test_docscrape.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/numpydoc/tests/test_docscrape.py b/numpydoc/tests/test_docscrape.py index 902c3f1d..143f9d65 100644 --- a/numpydoc/tests/test_docscrape.py +++ b/numpydoc/tests/test_docscrape.py @@ -631,13 +631,13 @@ def test_parameters_without_extended_description(): def test_escape_stars(): signature = str(doc3).split('\n')[0] - assert signature == 'my_signature(\*params, \*\*kwds)' + assert signature == r'my_signature(\*params, \*\*kwds)' def my_func(a, b, **kwargs): pass fdoc = FunctionDoc(func=my_func) - assert fdoc['Signature'] == 'my_func(a, b, \*\*kwargs)' + assert fdoc['Signature'] == r'my_func(a, b, \*\*kwargs)' doc4 = NumpyDocString( @@ -1238,7 +1238,7 @@ def test_args_and_kwargs(): **kwargs : dict Keyword arguments """, config=cfg) - line_by_line_compare(str(doc), """ + line_by_line_compare(str(doc), r""" :Parameters: **param1** : int