OLD | NEW |
1 # Copyright 2014 Google Inc. | 1 # Copyright 2014 Google Inc. |
2 # This program is free software; you can redistribute it and/or modify it under | 2 # This program is free software; you can redistribute it and/or modify it under |
3 # the terms of the GNU General Public License as published by the Free Software | 3 # the terms of the GNU General Public License as published by the Free Software |
4 # Foundation; either version 2 of the License, or (at your option) any later | 4 # Foundation; either version 2 of the License, or (at your option) any later |
5 # version. | 5 # version. |
6 # | 6 # |
7 # This program is distributed in the hope that it will be useful, but WITHOUT | 7 # This program is distributed in the hope that it will be useful, but WITHOUT |
8 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 8 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
9 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | 9 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
10 # | 10 # |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 '(method is not used by Python 3)', | 245 '(method is not used by Python 3)', |
246 {'maxversion': (3, 0)}), | 246 {'maxversion': (3, 0)}), |
247 'W1631': ('map is used as implicitly evaluated call', | 247 'W1631': ('map is used as implicitly evaluated call', |
248 'implicit-map-evaluation', | 248 'implicit-map-evaluation', |
249 'Used when the map builtin is used as implicitly ' | 249 'Used when the map builtin is used as implicitly ' |
250 'evaluated call, as in "map(func, args)" on a single line. ' | 250 'evaluated call, as in "map(func, args)" on a single line. ' |
251 'This behaviour will not work in Python 3, where ' | 251 'This behaviour will not work in Python 3, where ' |
252 'map is a generator and must be evaluated. ' | 252 'map is a generator and must be evaluated. ' |
253 'Prefer a for-loop as alternative.', | 253 'Prefer a for-loop as alternative.', |
254 {'maxversion': (3, 0)}), | 254 {'maxversion': (3, 0)}), |
| 255 'W1632': ('input built-in referenced', |
| 256 'input-builtin', |
| 257 'Used when the input built-in is referenced ' |
| 258 '(backwards-incompatible semantics in Python 3)', |
| 259 {'maxversion': (3, 0)}), |
| 260 'W1633': ('round built-in referenced', |
| 261 'round-builtin', |
| 262 'Used when the round built-in is referenced ' |
| 263 '(backwards-incompatible semantics in Python 3)', |
| 264 {'maxversion': (3, 0)}), |
255 } | 265 } |
256 | 266 |
257 _missing_builtins = frozenset([ | 267 _bad_builtins = frozenset([ |
258 'apply', | 268 'apply', |
259 'basestring', | 269 'basestring', |
260 'buffer', | 270 'buffer', |
261 'cmp', | 271 'cmp', |
262 'coerce', | 272 'coerce', |
263 'execfile', | 273 'execfile', |
264 'file', | 274 'file', |
| 275 'input', # Not missing, but incompatible semantics |
265 'long', | 276 'long', |
266 'raw_input', | 277 'raw_input', |
267 'reduce', | 278 'reduce', |
| 279 'round', # Not missing, but incompatible semantics |
268 'StandardError', | 280 'StandardError', |
269 'unicode', | 281 'unicode', |
270 'xrange', | 282 'xrange', |
271 'reload', | 283 'reload', |
272 ]) | 284 ]) |
273 | 285 |
274 _unused_magic_methods = frozenset([ | 286 _unused_magic_methods = frozenset([ |
275 '__coerce__', | 287 '__coerce__', |
276 '__delslice__', | 288 '__delslice__', |
277 '__getslice__', | 289 '__getslice__', |
(...skipping 25 matching lines...) Expand all Loading... |
303 @utils.check_messages('implicit-map-evaluation') | 315 @utils.check_messages('implicit-map-evaluation') |
304 def visit_discard(self, node): | 316 def visit_discard(self, node): |
305 if (isinstance(node.value, astroid.CallFunc) and | 317 if (isinstance(node.value, astroid.CallFunc) and |
306 isinstance(node.value.func, astroid.Name) and | 318 isinstance(node.value.func, astroid.Name) and |
307 node.value.func.name == 'map'): | 319 node.value.func.name == 'map'): |
308 module = node.value.func.lookup('map')[0] | 320 module = node.value.func.lookup('map')[0] |
309 if getattr(module, 'name', None) == '__builtin__': | 321 if getattr(module, 'name', None) == '__builtin__': |
310 self.add_message('implicit-map-evaluation', node=node) | 322 self.add_message('implicit-map-evaluation', node=node) |
311 | 323 |
312 def visit_name(self, node): | 324 def visit_name(self, node): |
313 """Detect when a built-in that is missing in Python 3 is referenced.""" | 325 """Detect when a "bad" built-in is referenced.""" |
314 found_node = node.lookup(node.name)[0] | 326 found_node = node.lookup(node.name)[0] |
315 if getattr(found_node, 'name', None) == '__builtin__': | 327 if getattr(found_node, 'name', None) == '__builtin__': |
316 if node.name in self._missing_builtins: | 328 if node.name in self._bad_builtins: |
317 message = node.name.lower() + '-builtin' | 329 message = node.name.lower() + '-builtin' |
318 self.add_message(message, node=node) | 330 self.add_message(message, node=node) |
319 | 331 |
320 @utils.check_messages('print-statement') | 332 @utils.check_messages('print-statement') |
321 def visit_print(self, node): | 333 def visit_print(self, node): |
322 self.add_message('print-statement', node=node) | 334 self.add_message('print-statement', node=node) |
323 | 335 |
324 @utils.check_messages('no-absolute-import') | 336 @utils.check_messages('no-absolute-import') |
325 def visit_from(self, node): | 337 def visit_from(self, node): |
326 if node.modname == '__future__': | 338 if node.modname == '__future__': |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 self.add_message('long-suffix', line=start[0]) | 467 self.add_message('long-suffix', line=start[0]) |
456 elif _is_old_octal(token): | 468 elif _is_old_octal(token): |
457 self.add_message('old-octal-literal', line=start[0]) | 469 self.add_message('old-octal-literal', line=start[0]) |
458 if tokens[idx][1] == '<>': | 470 if tokens[idx][1] == '<>': |
459 self.add_message('old-ne-operator', line=tokens[idx][2][0]) | 471 self.add_message('old-ne-operator', line=tokens[idx][2][0]) |
460 | 472 |
461 | 473 |
462 def register(linter): | 474 def register(linter): |
463 linter.register_checker(Python3Checker(linter)) | 475 linter.register_checker(Python3Checker(linter)) |
464 linter.register_checker(Python3TokenChecker(linter)) | 476 linter.register_checker(Python3TokenChecker(linter)) |
OLD | NEW |