|
1 | | -#!/usr/bin/env python3 |
2 | 1 | import ast |
3 | 2 | from collections import namedtuple |
4 | 3 | from contextlib import suppress |
@@ -208,6 +207,10 @@ def visit_For(self, node): |
208 | 207 | self.check_for_b007(node) |
209 | 208 | self.generic_visit(node) |
210 | 209 |
|
| 210 | + def visit_Assert(self, node): |
| 211 | + self.check_for_b011(node) |
| 212 | + self.generic_visit(node) |
| 213 | + |
211 | 214 | def visit_AsyncFunctionDef(self, node): |
212 | 215 | self.check_for_b902(node) |
213 | 216 | self.check_for_b006(node) |
@@ -273,6 +276,10 @@ def check_for_b007(self, node): |
273 | 276 | n = targets.names[name][0] |
274 | 277 | self.errors.append(B007(n.lineno, n.col_offset, vars=(name,))) |
275 | 278 |
|
| 279 | + def check_for_b011(self, node): |
| 280 | + if isinstance(node.test, ast.NameConstant) and node.test.value is False: |
| 281 | + self.errors.append(B011(node.lineno, node.col_offset)) |
| 282 | + |
276 | 283 | def check_for_b901(self, node): |
277 | 284 | xs = list(node.body) |
278 | 285 | has_yield = False |
@@ -494,6 +501,10 @@ def visit(self, node): |
494 | 501 | message="B010 Do not call setattr with a constant attribute value, " |
495 | 502 | "it is not any safer than normal property access." |
496 | 503 | ) |
| 504 | +B011 = Error( |
| 505 | + message="B011 Do not call assert False since python -O removes these calls. " |
| 506 | + "Instead callers should raise AssertionError()." |
| 507 | +) |
497 | 508 |
|
498 | 509 |
|
499 | 510 | # Those could be false positives but it's more dangerous to let them slip |
@@ -552,7 +563,7 @@ def visit(self, node): |
552 | 563 | B902.implicit_classmethods = {"__new__", "__init_subclass__", "__class_getitem__"} |
553 | 564 | B902.self = ["self"] # it's a list because the first is preferred |
554 | 565 | B902.cls = ["cls", "klass"] # ditto. |
555 | | -B902.metacls = ["metacls", "metaclass", "typ"] # ditto. |
| 566 | +B902.metacls = ["metacls", "metaclass", "typ", "mcs"] # ditto. |
556 | 567 |
|
557 | 568 | B903 = Error( |
558 | 569 | message="B903 Data class should either be immutable or use __slots__ to " |
|
0 commit comments