1616.. [1] https://github.com/numpy/numpydoc
1717
1818"""
19- from __future__ import division , absolute_import , print_function
20-
2119from copy import deepcopy
22- import sys
2320import re
2421import pydoc
2522import inspect
26- try :
27- from collections .abc import Callable
28- except ImportError :
29- from collections import Callable
23+ from collections .abc import Callable
3024import hashlib
3125import itertools
3226
3529from sphinx .addnodes import pending_xref , desc_content
3630from sphinx .util import logging
3731
38- if sphinx .__version__ < '1.0.1 ' :
39- raise RuntimeError ("Sphinx 1.0.1 or newer is required" )
32+ if sphinx .__version__ < '1.6.5 ' :
33+ raise RuntimeError ("Sphinx 1.6.5 or newer is required" )
4034
4135from .docscrape_sphinx import get_doc_object
4236from .xref import DEFAULT_LINKS
4337from . import __version__
4438
4539logger = logging .getLogger (__name__ )
4640
47- if sys .version_info [0 ] >= 3 :
48- sixu = lambda s : s
49- else :
50- sixu = lambda s : unicode (s , 'unicode_escape' )
51-
52-
5341HASH_LEN = 12
5442
5543def rename_references (app , what , name , obj , options , lines ):
@@ -58,7 +46,7 @@ def rename_references(app, what, name, obj, options, lines):
5846 references = set ()
5947 for line in lines :
6048 line = line .strip ()
61- m = re .match (sixu ( r'^\.\. +\[(%s)\]' ) %
49+ m = re .match (r'^\.\. +\[(%s)\]' %
6250 app .config .numpydoc_citation_re ,
6351 line , re .I )
6452 if m :
@@ -73,10 +61,10 @@ def rename_references(app, what, name, obj, options, lines):
7361 for r in references :
7462 new_r = prefix + '-' + r
7563 for i , line in enumerate (lines ):
76- lines [i ] = lines [i ].replace (sixu ( '[%s]_' ) % r ,
77- sixu ( '[%s]_' ) % new_r )
78- lines [i ] = lines [i ].replace (sixu ( '.. [%s]' ) % r ,
79- sixu ( '.. [%s]' ) % new_r )
64+ lines [i ] = lines [i ].replace ('[%s]_' % r ,
65+ '[%s]_' % new_r )
66+ lines [i ] = lines [i ].replace ('.. [%s]' % r ,
67+ '.. [%s]' % new_r )
8068
8169
8270def _is_cite_in_numpydoc_docstring (citation_node ):
@@ -166,33 +154,29 @@ def mangle_docstrings(app, what, name, obj, options, lines):
166154 }
167155
168156 cfg .update (options or {})
169- u_NL = sixu ( '\n ' )
157+ u_NL = '\n '
170158 if what == 'module' :
171159 # Strip top title
172160 pattern = '^\\ s*[#*=]{4,}\\ n[a-z0-9 -]+\\ n[#*=]{4,}\\ s*'
173- title_re = re .compile (sixu ( pattern ) , re .I | re .S )
174- lines [:] = title_re .sub (sixu ( '' ) , u_NL .join (lines )).split (u_NL )
161+ title_re = re .compile (pattern , re .I | re .S )
162+ lines [:] = title_re .sub ('' , u_NL .join (lines )).split (u_NL )
175163 else :
176164 try :
177165 doc = get_doc_object (obj , what , u_NL .join (lines ), config = cfg ,
178166 builder = app .builder )
179- if sys .version_info [0 ] >= 3 :
180- doc = str (doc )
181- else :
182- doc = unicode (doc )
183- lines [:] = doc .split (u_NL )
167+ lines [:] = str (doc ).split (u_NL )
184168 except :
185169 logger .error ('[numpydoc] While processing docstring for %r' , name )
186170 raise
187171
188172 if (app .config .numpydoc_edit_link and hasattr (obj , '__name__' ) and
189173 obj .__name__ ):
190174 if hasattr (obj , '__module__' ):
191- v = dict (full_name = sixu ( "%s.%s" ) % (obj .__module__ , obj .__name__ ))
175+ v = dict (full_name = "%s.%s" % (obj .__module__ , obj .__name__ ))
192176 else :
193177 v = dict (full_name = obj .__name__ )
194- lines += [sixu ( '' ), sixu ( '.. htmlonly::' ), sixu ( '' ) ]
195- lines += [sixu ( ' %s' ) % x for x in
178+ lines += ['' , '.. htmlonly::' , '' ]
179+ lines += [' %s' % x for x in
196180 (app .config .numpydoc_edit_link % v ).split ("\n " )]
197181
198182 # call function to replace reference numbers so that there are no
@@ -218,8 +202,8 @@ def mangle_signature(app, what, name, obj, options, sig, retann):
218202 doc = get_doc_object (obj , config = {'show_class_members' : False })
219203 sig = doc ['Signature' ] or getattr (obj , '__text_signature__' , None )
220204 if sig :
221- sig = re .sub (sixu ( "^[^(]*" ), sixu ( "" ) , sig )
222- return sig , sixu ( '' )
205+ sig = re .sub ("^[^(]*" , "" , sig )
206+ return sig , ''
223207
224208
225209def setup (app , get_doc_object_ = get_doc_object ):
0 commit comments