From 67fbfdda268d946e19cd5730e17e797694dee572 Mon Sep 17 00:00:00 2001 From: Joel Nothman Date: Wed, 13 Jun 2018 17:26:07 +1000 Subject: [PATCH] FIX deprecated use of string escapes --- numpydoc/docscrape.py | 10 +++++----- numpydoc/docscrape_sphinx.py | 2 +- numpydoc/tests/test_docscrape.py | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/numpydoc/docscrape.py b/numpydoc/docscrape.py index 598b4438..bc6f9284 100644 --- a/numpydoc/docscrape.py +++ b/numpydoc/docscrape.py @@ -31,7 +31,7 @@ def __init__(self, data): Parameters ---------- data : str - String with lines separated by '\n'. + String with lines separated by '\\n'. """ if isinstance(data, list): @@ -317,7 +317,7 @@ 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): + if re.compile(r'^([\w., ]+=)?\s*[\w\.]+\(.*\)$').match(summary_str): self['Signature'] = summary_str if not self._is_at_section(): continue @@ -389,7 +389,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 [''] @@ -521,7 +521,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 @@ -538,7 +538,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 257a61e4..20cf7f5a 100644 --- a/numpydoc/docscrape_sphinx.py +++ b/numpydoc/docscrape_sphinx.py @@ -164,7 +164,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/tests/test_docscrape.py b/numpydoc/tests/test_docscrape.py index 227ee643..43b3d645 100644 --- a/numpydoc/tests/test_docscrape.py +++ b/numpydoc/tests/test_docscrape.py @@ -632,13 +632,13 @@ def test_parameters_without_extended_description(): def test_escape_stars(): signature = str(doc3).split('\n')[0] - assert_equal(signature, 'my_signature(\*params, \*\*kwds)') + assert_equal(signature, r'my_signature(\*params, \*\*kwds)') def my_func(a, b, **kwargs): pass fdoc = FunctionDoc(func=my_func) - assert_equal(fdoc['Signature'], 'my_func(a, b, \*\*kwargs)') + assert_equal(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