@@ -122,6 +122,23 @@ def code_mapping(
122122 return default
123123
124124
125+ def special_case_unescaped (docstring , variable ):
126+ """Can RST213 for ``*arg``, or RST210 for ``*kwarg`` be ignored."""
127+ if "\n Args:\n " in docstring and docstring .find ("\n Args:\n " ) < docstring .find (
128+ f" { variable } :"
129+ ):
130+ # Ignore special case used in Google docstring style
131+ return True
132+ elif "\n Parameters\n ----------\n " in docstring :
133+ i = docstring .find ("\n Parameters\n ----------\n " )
134+ if i < docstring .find (f"\n { variable } \n " ) or i < docstring .find (
135+ f"\n { variable } :"
136+ ):
137+ # Ignore special case used in NumPy docstring style
138+ return True
139+ return False
140+
141+
125142class reStructuredTextChecker :
126143 """Checker of Python docstrings as reStructuredText."""
127144
@@ -256,38 +273,14 @@ def run(self):
256273 code += 100 * rst_error .level
257274 msg = "%s%03i %s" % (rst_prefix , code , msg )
258275
259- if code == 210 :
260- if "\n Args:\n " in docstring and docstring .find (
261- "\n Args:\n "
262- ) < docstring .find (" **kwargs:" ):
263- # Ignore special case used in Google docstring style
264- continue
265- if "\n Parameters\n ----------\n " in docstring and docstring .find (
266- "\n Parameters\n ----------\n "
267- ) < docstring .find ("\n **kwargs\n " ):
268- # Ignore special case used in NumPy docstring style
269- continue
270- if "\n Parameters\n ----------\n " in docstring and docstring .find (
271- "\n Parameters\n ----------\n "
272- ) < docstring .find ("\n **kwargs :" ):
273- # Ignore special case used in NumPy docstring style
274- continue
275- elif code == 213 :
276- if "\n Args:\n " in docstring and docstring .find (
277- "\n Args:\n "
278- ) < docstring .find (" *args:" ):
279- # Ignore special case used in Google docstring style
280- continue
281- if "\n Parameters\n ----------\n " in docstring and docstring .find (
282- "\n Parameters\n ----------\n "
283- ) < docstring .find ("\n *args\n " ):
284- # Ignore special case used in NumPy docstring style
285- continue
286- if "\n Parameters\n ----------\n " in docstring and docstring .find (
287- "\n Parameters\n ----------\n "
288- ) < docstring .find ("\n *args :" ):
289- # Ignore special case used in NumPy docstring style
290- continue
276+ # Silence special case use of *args and **kwargs
277+ # (hopefully won't mask a true positive in same docstring)
278+ if code == 210 and special_case_unescaped (docstring , "**kwargs" ):
279+ # Ignore special case used in Google/NumPy docstring style
280+ continue
281+ elif code == 213 and special_case_unescaped (docstring , "*args" ):
282+ # Ignore special case used in Google/NumPy docstring style
283+ continue
291284
292285 # We don't know the column number, leaving as zero.
293286 yield start + rst_error .line , 0 , msg , type (self )
0 commit comments