| OLD | NEW |
| 1 # This file is part of Adblock Plus <https://adblockplus.org/>, | 1 # This file is part of Adblock Plus <https://adblockplus.org/>, |
| 2 # Copyright (C) 2006-2016 Eyeo GmbH | 2 # Copyright (C) 2006-2016 Eyeo GmbH |
| 3 # | 3 # |
| 4 # Adblock Plus is free software: you can redistribute it and/or modify | 4 # Adblock Plus is free software: you can redistribute it and/or modify |
| 5 # it under the terms of the GNU General Public License version 3 as | 5 # it under the terms of the GNU General Public License version 3 as |
| 6 # published by the Free Software Foundation. | 6 # published by the Free Software Foundation. |
| 7 # | 7 # |
| 8 # Adblock Plus is distributed in the hope that it will be useful, | 8 # Adblock Plus is distributed in the hope that it will be useful, |
| 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 substitute = DISCOURAGED_APIS.get(name) | 277 substitute = DISCOURAGED_APIS.get(name) |
| 278 if substitute: | 278 if substitute: |
| 279 self.errors.append((node, 'A301 use {}() instead of ' | 279 self.errors.append((node, 'A301 use {}() instead of ' |
| 280 '{}()'.format(substitute, name))) | 280 '{}()'.format(substitute, name))) |
| 281 | 281 |
| 282 def visit_Call(self, node): | 282 def visit_Call(self, node): |
| 283 func = get_identifier(node.func) | 283 func = get_identifier(node.func) |
| 284 arg = next(iter(node.args), None) | 284 arg = next(iter(node.args), None) |
| 285 redundant_literal = False | 285 redundant_literal = False |
| 286 | 286 |
| 287 if isinstance(arg, ast.Lambda) and func in {'map', 'filter', | 287 if isinstance(arg, ast.Lambda): |
| 288 'imap', 'ifilter', | 288 if len(node.args) == 2 and func in {'map', 'filter', |
| 289 'itertools.imap', | 289 'imap', 'ifilter', |
| 290 'itertools.ifilter'}: | 290 'itertools.imap', |
| 291 self.errors.append((node, 'A104 use a comprehension ' | 291 'itertools.ifilter'}: |
| 292 'instead of calling {}() with ' | 292 self.errors.append((node, 'A104 use a comprehension ' |
| 293 'lambda function'.format(func))) | 293 'instead of calling {}() with ' |
| 294 'lambda function'.format(func))) |
| 294 elif isinstance(arg, (ast.List, ast.Tuple)): | 295 elif isinstance(arg, (ast.List, ast.Tuple)): |
| 295 if func == 'dict': | 296 if func == 'dict': |
| 296 redundant_literal = all(isinstance(elt, (ast.Tuple, ast.List)) | 297 redundant_literal = all(isinstance(elt, (ast.Tuple, ast.List)) |
| 297 for elt in arg.elts) | 298 for elt in arg.elts) |
| 298 else: | 299 else: |
| 299 redundant_literal = func in {'list', 'set', 'tuple'} | 300 redundant_literal = func in {'list', 'set', 'tuple'} |
| 300 elif isinstance(arg, (ast.ListComp, ast.GeneratorExp)): | 301 elif isinstance(arg, (ast.ListComp, ast.GeneratorExp)): |
| 301 if func == 'dict': | 302 if func == 'dict': |
| 302 redundant_literal = isinstance(arg.elt, (ast.Tuple, ast.List)) | 303 redundant_literal = isinstance(arg.elt, (ast.Tuple, ast.List)) |
| 303 else: | 304 else: |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 if tokens[i + 1][:2] != (tokenize.OP, ':'): | 463 if tokens[i + 1][:2] != (tokenize.OP, ':'): |
| 463 break | 464 break |
| 464 | 465 |
| 465 return [(pos, 'A111 redundant parenthesis for {} ' | 466 return [(pos, 'A111 redundant parenthesis for {} ' |
| 466 'statement'.format(statement))] | 467 'statement'.format(statement))] |
| 467 | 468 |
| 468 return [] | 469 return [] |
| 469 | 470 |
| 470 check_redundant_parenthesis.name = 'abp-redundant-parenthesis' | 471 check_redundant_parenthesis.name = 'abp-redundant-parenthesis' |
| 471 check_redundant_parenthesis.version = __version__ | 472 check_redundant_parenthesis.version = __version__ |
| OLD | NEW |