Skip to content

Commit 1f197e3

Browse files
larsonerjnothman
authored andcommitted
FIX: Escape chars in re (#194)
1 parent d7ca480 commit 1f197e3

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

numpydoc/docscrape.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,8 @@ def _parse_summary(self):
324324
while True:
325325
summary = self._doc.read_to_next_empty_line()
326326
summary_str = " ".join([s.strip() for s in summary]).strip()
327-
if re.compile('^([\w., ]+=)?\s*[\w\.]+\(.*\)$').match(summary_str):
327+
compiled = re.compile(r'^([\w., ]+=)?\s*[\w\.]+\(.*\)$')
328+
if compiled.match(summary_str):
328329
self['Signature'] = summary_str
329330
if not self._is_at_section():
330331
continue
@@ -396,7 +397,7 @@ def _str_indent(self, doc, indent=4):
396397

397398
def _str_signature(self):
398399
if self['Signature']:
399-
return [self['Signature'].replace('*', '\*')] + ['']
400+
return [self['Signature'].replace('*', r'\*')] + ['']
400401
else:
401402
return ['']
402403

@@ -528,7 +529,7 @@ def __init__(self, func, role='func', doc=None, config={}):
528529
else:
529530
argspec = inspect.getargspec(func)
530531
signature = inspect.formatargspec(*argspec)
531-
signature = '%s%s' % (func_name, signature.replace('*', '\*'))
532+
signature = '%s%s' % (func_name, signature.replace('*', r'\*'))
532533
except TypeError:
533534
signature = '%s()' % func_name
534535
self['Signature'] = signature
@@ -545,7 +546,7 @@ def __str__(self):
545546
out = ''
546547

547548
func, func_name = self.get_func()
548-
signature = self['Signature'].replace('*', '\*')
549+
signature = self['Signature'].replace('*', r'\*')
549550

550551
roles = {'func': 'function',
551552
'meth': 'method'}

numpydoc/docscrape_sphinx.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def _process_param(self, param, desc, fake_autosummary):
168168
param)
169169
if obj_doc:
170170
# Overwrite desc. Take summary logic of autosummary
171-
desc = re.split('\n\s*\n', obj_doc.strip(), 1)[0]
171+
desc = re.split(r'\n\s*\n', obj_doc.strip(), 1)[0]
172172
# XXX: Should this have DOTALL?
173173
# It does not in autosummary
174174
m = re.search(r"^([A-Z].*?\.)(?:\s|$)",

numpydoc/numpydoc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def rename_references(app, what, name, obj, options, lines):
5353
references = set()
5454
for line in lines:
5555
line = line.strip()
56-
m = re.match(sixu('^.. \\[(%s)\\]') % app.config.numpydoc_citation_re,
56+
m = re.match(sixu(r'^.. \[(%s)\]') % app.config.numpydoc_citation_re,
5757
line, re.I)
5858
if m:
5959
references.add(m.group(1))

numpydoc/tests/test_docscrape.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -631,13 +631,13 @@ def test_parameters_without_extended_description():
631631

632632
def test_escape_stars():
633633
signature = str(doc3).split('\n')[0]
634-
assert signature == 'my_signature(\*params, \*\*kwds)'
634+
assert signature == r'my_signature(\*params, \*\*kwds)'
635635

636636
def my_func(a, b, **kwargs):
637637
pass
638638

639639
fdoc = FunctionDoc(func=my_func)
640-
assert fdoc['Signature'] == 'my_func(a, b, \*\*kwargs)'
640+
assert fdoc['Signature'] == r'my_func(a, b, \*\*kwargs)'
641641

642642

643643
doc4 = NumpyDocString(
@@ -1238,7 +1238,7 @@ def test_args_and_kwargs():
12381238
**kwargs : dict
12391239
Keyword arguments
12401240
""", config=cfg)
1241-
line_by_line_compare(str(doc), """
1241+
line_by_line_compare(str(doc), r"""
12421242
:Parameters:
12431243
12441244
**param1** : int

0 commit comments

Comments
 (0)