annotate Tools/scripts/checkappend.py @ 45888:51e24512e305

- Issue #719888: Updated tokenize to use a bytes API. generate_tokens has been renamed tokenize and now works with bytes rather than strings. A new detect_encoding function has been added for determining source file encoding according to PEP-0263. Token sequences returned by tokenize always start with an ENCODING token which specifies the encoding used to decode the file. This token is used to encode the output of untokenize back to bytes. Credit goes to Michael "I'm-going-to-name-my-first-child-unittest" Foord from Resolver Systems for this work.
author Trent Nelson <trent.nelson@snakebite.org>
date Tue, 18 Mar 2008 22:41:35 +0000
parents 46625e6122e9
children fcfe324663a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11879
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 #! /usr/bin/env python
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 # Released to the public domain, by Tim Peters, 28 February 2000.
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 """checkappend.py -- search for multi-argument .append() calls.
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 Usage: specify one or more file or directory paths:
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 checkappend [-v] file_or_dir [file_or_dir] ...
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 Each file_or_dir is checked for multi-argument .append() calls. When
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 a directory, all .py files in the directory, and recursively in its
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 subdirectories, are checked.
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 Use -v for status msgs. Use -vv for more status msgs.
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 In the absence of -v, the only output is pairs of the form
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 filename(linenumber):
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 line containing the suspicious append
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
20
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 Note that this finds multi-argument append calls regardless of whether
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 they're attached to list objects. If a module defines a class with an
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 append method that takes more than one argument, calls to that method
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 will be listed.
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
25
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 Note that this will not find multi-argument list.append calls made via a
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 bound method object. For example, this is not caught:
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
28
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 somelist = []
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 push = somelist.append
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 push(1, 2, 3)
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 """
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 __version__ = 1, 0, 0
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 import os
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 import sys
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 import getopt
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 import tokenize
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
40
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 verbose = 0
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
42
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 def errprint(*args):
25219
8a7a2f1f88f0 Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents: 11880
diff changeset
44 msg = ' '.join(args)
11879
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 sys.stderr.write(msg)
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 sys.stderr.write("\n")
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
47
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 def main():
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 args = sys.argv[1:]
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 global verbose
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 try:
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 opts, args = getopt.getopt(sys.argv[1:], "v")
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 31515
diff changeset
53 except getopt.error as msg:
11880
d27684ab215a Correct type error in getopt.error handling code.
Guido van Rossum <guido@python.org>
parents: 11879
diff changeset
54 errprint(str(msg) + "\n\n" + __doc__)
11879
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 return
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 for opt, optarg in opts:
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 if opt == '-v':
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 verbose = verbose + 1
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 if not args:
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 errprint(__doc__)
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 return
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 for arg in args:
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 check(arg)
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
64
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 def check(file):
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 if os.path.isdir(file) and not os.path.islink(file):
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 if verbose:
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 40587
diff changeset
68 print("%r: listing directory" % (file,))
11879
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 names = os.listdir(file)
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 for name in names:
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 fullname = os.path.join(file, name)
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 if ((os.path.isdir(fullname) and
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 not os.path.islink(fullname))
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 or os.path.normcase(name[-3:]) == ".py"):
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 check(fullname)
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 return
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
77
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 try:
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 f = open(file)
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 31515
diff changeset
80 except IOError as msg:
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
81 errprint("%r: I/O Error: %s" % (file, msg))
11879
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 return
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
83
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 if verbose > 1:
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 40587
diff changeset
85 print("checking %r ..." % (file,))
11879
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
86
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 ok = AppendChecker(file, f).run()
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 if verbose and ok:
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 40587
diff changeset
89 print("%r: Clean bill of health." % (file,))
11879
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
90
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 [FIND_DOT,
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 FIND_APPEND,
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 FIND_LPAREN,
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 FIND_COMMA,
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 FIND_STMT] = range(5)
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
96
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 class AppendChecker:
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 def __init__(self, fname, file):
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 self.fname = fname
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 self.file = file
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 self.state = FIND_DOT
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 self.nerrors = 0
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
103
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 def run(self):
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 try:
45888
51e24512e305 - Issue #719888: Updated tokenize to use a bytes API. generate_tokens has been
Trent Nelson <trent.nelson@snakebite.org>
parents: 42427
diff changeset
106 tokens = tokenize.generate_tokens(self.file.readline)
51e24512e305 - Issue #719888: Updated tokenize to use a bytes API. generate_tokens has been
Trent Nelson <trent.nelson@snakebite.org>
parents: 42427
diff changeset
107 for _token in tokens:
51e24512e305 - Issue #719888: Updated tokenize to use a bytes API. generate_tokens has been
Trent Nelson <trent.nelson@snakebite.org>
parents: 42427
diff changeset
108 self.tokeneater(*_token)
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 31515
diff changeset
109 except tokenize.TokenError as msg:
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
110 errprint("%r: Token Error: %s" % (self.fname, msg))
11879
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 self.nerrors = self.nerrors + 1
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 return self.nerrors == 0
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
113
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 def tokeneater(self, type, token, start, end, line,
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 NEWLINE=tokenize.NEWLINE,
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 JUNK=(tokenize.COMMENT, tokenize.NL),
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 OP=tokenize.OP,
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 NAME=tokenize.NAME):
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
119
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 state = self.state
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
121
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 if type in JUNK:
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 pass
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
124
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 elif state is FIND_DOT:
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 if type is OP and token == ".":
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 state = FIND_APPEND
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
128
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 elif state is FIND_APPEND:
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 if type is NAME and token == "append":
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 self.line = line
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 self.lineno = start[0]
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 state = FIND_LPAREN
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 else:
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 state = FIND_DOT
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
136
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 elif state is FIND_LPAREN:
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 if type is OP and token == "(":
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 self.level = 1
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 state = FIND_COMMA
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 else:
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 state = FIND_DOT
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
143
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 elif state is FIND_COMMA:
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 if type is OP:
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 if token in ("(", "{", "["):
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 self.level = self.level + 1
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 elif token in (")", "}", "]"):
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 self.level = self.level - 1
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 if self.level == 0:
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 state = FIND_DOT
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 elif token == "," and self.level == 1:
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 self.nerrors = self.nerrors + 1
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 40587
diff changeset
154 print("%s(%d):\n%s" % (self.fname, self.lineno,
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 40587
diff changeset
155 self.line))
11879
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 # don't gripe about this stmt again
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 state = FIND_STMT
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
158
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 elif state is FIND_STMT:
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 if type is NEWLINE:
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 state = FIND_DOT
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
162
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 else:
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
164 raise SystemError("unknown internal state '%r'" % (state,))
11879
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
165
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 self.state = state
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
167
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 if __name__ == '__main__':
a7d609ea90cc Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 main()