Skip to content

Commit 144c269

Browse files
committed
Update the suspicious builder to detect unused rules, and remove currently unusued rules.
1 parent 75da357 commit 144c269

File tree

2 files changed

+11
-40
lines changed

2 files changed

+11
-40
lines changed

Doc/tools/sphinxext/susp-ignored.csv

-40
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
c-api/arg,,:ref,"PyArg_ParseTuple(args, ""O|O:ref"", &object, &callback)"
22
c-api/list,,:high,list[low:high]
3-
c-api/list,,:high,list[low:high] = itemlist
43
c-api/sequence,,:i2,o[i1:i2]
5-
c-api/sequence,,:i2,o[i1:i2] = v
6-
c-api/sequence,,:i2,del o[i1:i2]
74
c-api/unicode,,:end,str[start:end]
85
distutils/setupscript,,::,
96
extending/embedding,,:numargs,"if(!PyArg_ParseTuple(args, "":numargs""))"
107
extending/extending,,:set,"if (PyArg_ParseTuple(args, ""O:set_callback"", &temp)) {"
118
extending/extending,,:myfunction,"PyArg_ParseTuple(args, ""D:myfunction"", &c);"
129
extending/newtypes,,:call,"if (!PyArg_ParseTuple(args, ""sss:call"", &arg1, &arg2, &arg3)) {"
1310
extending/windows,,:initspam,/export:initspam
14-
howto/cporting,,:add,"if (!PyArg_ParseTuple(args, ""ii:add_ints"", &one, &two))"
1511
howto/cporting,,:encode,"if (!PyArg_ParseTuple(args, ""O:encode_object"", &myobj))"
1612
howto/cporting,,:say,"if (!PyArg_ParseTuple(args, ""U:say_hello"", &name))"
1713
howto/curses,,:black,"They are: 0:black, 1:red, 2:green, 3:yellow, 4:blue, 5:magenta, 6:cyan, and"
@@ -46,7 +42,6 @@ howto/logging,,:This,DEBUG:root:This message should go to the log file
4642
howto/regex,,::,
4743
howto/regex,,:foo,(?:foo)
4844
howto/urllib2,,:example,"for example ""joe@password:example.com"""
49-
howto/webservers,,.. image:,.. image:: http.png
5045
library/audioop,,:ipos,"# factor = audioop.findfactor(in_test[ipos*2:ipos*2+len(out_test)],"
5146
library/cookie,,`,!#$%&'*+-.^_`|~
5247
library/datetime,,:MM,
@@ -73,12 +68,6 @@ library/imaplib,,:SS,"""DD-Mmm-YYYY HH:MM:SS"
7368
library/itertools,,:stop,elements from seq[start:stop:step]
7469
library/itertools,,:step,elements from seq[start:stop:step]
7570
library/linecache,,:sys,"sys:x:3:3:sys:/dev:/bin/sh"
76-
library/logging,,:And,
77-
library/logging,,:package1,
78-
library/logging,,:package2,
79-
library/logging,,:root,
80-
library/logging,,:This,
81-
library/logging,,:port,host:port
8271
library/logging.handlers,,:port,host:port
8372
library/mmap,,:i2,obj[i1:i2]
8473
library/multiprocessing,,:queue,">>> QueueManager.register('get_queue', callable=lambda:queue)"
@@ -89,28 +78,20 @@ library/multiprocessing,,`,# `Pool.imap()` (which will save on the amount of cod
8978
library/multiprocessing,,`,# A test file for the `multiprocessing` package
9079
library/multiprocessing,,`,# A test of `multiprocessing.Pool` class
9180
library/multiprocessing,,`,# Add more tasks using `put()`
92-
library/multiprocessing,,`,# create server for a `HostManager` object
93-
library/multiprocessing,,`,# Depends on `multiprocessing` package -- tested with `processing-0.60`
9481
library/multiprocessing,,`,# in the original order then consider using `Pool.map()` or
9582
library/multiprocessing,,`,# Not sure if we should synchronize access to `socket.accept()` method by
9683
library/multiprocessing,,`,# object. (We import `multiprocessing.reduction` to enable this pickling.)
9784
library/multiprocessing,,`,# register the Foo class; make `f()` and `g()` accessible via proxy
9885
library/multiprocessing,,`,# register the Foo class; make `g()` and `_h()` accessible via proxy
9986
library/multiprocessing,,`,# register the generator function baz; use `GeneratorProxy` to make proxies
100-
library/multiprocessing,,`,`Cluster` is a subclass of `SyncManager` so it allows creation of
101-
library/multiprocessing,,`,`hostname` gives the name of the host. If hostname is not
102-
library/multiprocessing,,`,`slots` is used to specify the number of slots for processes on
10387
library/optparse,,:len,"del parser.rargs[:len(value)]"
10488
library/os.path,,:foo,c:foo
105-
library/parser,,`,"""Make a function that raises an argument to the exponent `exp`."""
106-
library/pdb,,:lineno,filename:lineno
10789
library/pdb,,:lineno,filename:lineno
10890
library/posix,,`,"CFLAGS=""`getconf LFS_CFLAGS`"" OPT=""-g -O2 $CFLAGS"""
10991
library/profile,,:lineno,ncalls tottime percall cumtime percall filename:lineno(function)
11092
library/profile,,:lineno,filename:lineno(function)
11193
library/pyexpat,,:elem1,<py:elem1 />
11294
library/pyexpat,,:py,"xmlns:py = ""http://www.python.org/ns/"">"
113-
library/repr,,`,"return `obj`"
11495
library/smtplib,,:port,"as well as a regular host:port server."
11596
library/socket,,::,'5aef:2b::8'
11697
library/sqlite3,,:memory,
@@ -124,8 +105,6 @@ library/ssl,,:ops,Email Address []:ops@myserver.mygroup.myorganization.com
124105
library/ssl,,:Some,"Locality Name (eg, city) []:Some City"
125106
library/ssl,,:US,Country Name (2 letter code) [AU]:US
126107
library/stdtypes,,:len,s[len(s):len(s)]
127-
library/stdtypes,,:len,s[len(s):len(s)]
128-
library/string,,:end,s[start:end]
129108
library/string,,:end,s[start:end]
130109
library/subprocess,,`,"output=`mycmd myarg`"
131110
library/subprocess,,`,"output=`dmesg | grep hda`"
@@ -147,13 +126,8 @@ license,,`,THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AN
147126
reference/datamodel,,:step,a[i:j:step]
148127
reference/datamodel,,:max,
149128
reference/expressions,,:index,x[index:index]
150-
reference/expressions,,:datum,{key:datum...}
151129
reference/expressions,,`,`expressions...`
152130
reference/expressions,,`,"""`"""
153-
reference/expressions,,`,"""`"""
154-
reference/grammar,,:output,#diagram:output
155-
reference/grammar,,:rules,#diagram:rules
156-
reference/grammar,,:token,#diagram:token
157131
reference/grammar,,`,'`' testlist1 '`'
158132
reference/lexical_analysis,,:fileencoding,# vim:fileencoding=<encoding-name>
159133
reference/lexical_analysis,,`,", : . ` = ;"
@@ -176,8 +150,6 @@ using/cmdline,,:line,action:message:category:module:line
176150
using/cmdline,,:message,action:message:category:module:line
177151
using/cmdline,,:module,action:message:category:module:line
178152
using/cmdline,,:errorhandler,:errorhandler
179-
using/windows,162,`,`` this fixes syntax highlighting errors in some editors due to the \\\\ hackery
180-
using/windows,170,`,``
181153
whatsnew/2.0,418,:len,
182154
whatsnew/2.3,,::,
183155
whatsnew/2.3,,:config,
@@ -191,30 +163,18 @@ whatsnew/2.4,,:System,
191163
whatsnew/2.5,,:memory,:memory:
192164
whatsnew/2.5,,:step,[start:stop:step]
193165
whatsnew/2.5,,:stop,[start:stop:step]
194-
distutils/examples,267,`,This is the description of the ``foobar`` package.
195166
faq/programming,,:reduce,"print (lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+y,map(lambda y,"
196167
faq/programming,,:reduce,"Sx=Sx,Sy=Sy:reduce(lambda x,y:x+y,map(lambda x,xc=Ru,yc=yc,Ru=Ru,Ro=Ro,"
197168
faq/programming,,:chr,">=4.0) or 1+f(xc,yc,x*x-y*y+xc,2.0*x*y+yc,k-1,f):f(xc,yc,x,y,k,f):chr("
198169
faq/programming,,::,for x in sequence[::-1]:
199-
faq/windows,229,:EOF,@setlocal enableextensions & python -x %~f0 %* & goto :EOF
200-
faq/windows,393,:REG,.py :REG_SZ: c:\<path to python>\python.exe -u %s %s
201170
library/bisect,,:hi,all(val >= x for val in a[i:hi])
202171
library/bisect,,:hi,all(val > x for val in a[i:hi])
203-
library/http.client,52,:port,host:port
204-
library/nntplib,,:bytes,:bytes
205-
library/nntplib,,:lines,:lines
206-
library/nntplib,,:lines,"['xref', 'from', ':lines', ':bytes', 'references', 'date', 'message-id', 'subject']"
207-
library/nntplib,,:bytes,"['xref', 'from', ':lines', ':bytes', 'references', 'date', 'message-id', 'subject']"
208-
library/pickle,567,:memory,"conn = sqlite3.connect("":memory:"")"
209-
library/profile,293,:lineno,"(sort by filename:lineno),"
210172
library/socket,,::,"(10, 1, 6, '', ('2001:888:2000:d::a2', 80, 0, 0))]"
211173
library/stdtypes,,:end,s[start:end]
212-
library/stdtypes,,:end,s[start:end]
213174
license,,`,* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
214175
license,,`,* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
215176
license,,`,"``Software''), to deal in the Software without restriction, including"
216177
license,,`,"THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,"
217-
reference/lexical_analysis,704,`,$ ? `
218178
whatsnew/2.7,735,:Sunday,'2009:4:Sunday'
219179
whatsnew/2.7,862,::,"export PYTHONWARNINGS=all,error:::Cookie:0"
220180
whatsnew/2.7,862,:Cookie,"export PYTHONWARNINGS=all,error:::Cookie:0"

Doc/tools/sphinxext/suspicious.py

+11
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ def __init__(self, docname, lineno, issue, line):
6666
# None -> don't care
6767
self.issue = issue # the markup fragment that triggered this rule
6868
self.line = line # text of the container element (single line only)
69+
self.used = False
70+
71+
def __repr__(self):
72+
return '{0.docname},,{0.issue},{0.line}'.format(self)
6973

7074

7175

@@ -105,6 +109,12 @@ def write_doc(self, docname, doctree):
105109
doctree.walk(visitor)
106110

107111
def finish(self):
112+
unused_rules = [rule for rule in self.rules if not rule.used]
113+
if unused_rules:
114+
self.warn('Found %s/%s unused rules:' %
115+
(len(unused_rules), len(self.rules)))
116+
for rule in unused_rules:
117+
self.info(repr(rule))
108118
return
109119

110120
def check_issue(self, line, lineno, issue):
@@ -129,6 +139,7 @@ def is_ignored(self, line, lineno, issue):
129139
if (rule.lineno is not None) and \
130140
abs(rule.lineno - lineno) > 5: continue
131141
# if it came this far, the rule matched
142+
rule.used = True
132143
return True
133144
return False
134145

0 commit comments

Comments
 (0)