|
5 | 5 |
|
6 | 6 | from __future__ import annotations
|
7 | 7 |
|
| 8 | +from collections import defaultdict |
8 | 9 | from typing_extensions import Final
|
9 | 10 |
|
10 | 11 | error_codes: dict[str, ErrorCode] = {}
|
| 12 | +sub_code_map: dict[str, set[str]] = defaultdict(set) |
11 | 13 |
|
12 | 14 |
|
13 | 15 | class ErrorCode:
|
14 | 16 | def __init__(
|
15 |
| - self, code: str, description: str, category: str, default_enabled: bool = True |
| 17 | + self, |
| 18 | + code: str, |
| 19 | + description: str, |
| 20 | + category: str, |
| 21 | + default_enabled: bool = True, |
| 22 | + sub_code_of: ErrorCode | None = None, |
16 | 23 | ) -> None:
|
17 | 24 | self.code = code
|
18 | 25 | self.description = description
|
19 | 26 | self.category = category
|
20 | 27 | self.default_enabled = default_enabled
|
| 28 | + self.sub_code_of = sub_code_of |
| 29 | + if sub_code_of is not None: |
| 30 | + assert sub_code_of.sub_code_of is None, "Nested subcategories are not supported" |
| 31 | + sub_code_map[sub_code_of.code].add(code) |
21 | 32 | error_codes[code] = self
|
22 | 33 |
|
23 | 34 | def __str__(self) -> str:
|
@@ -51,6 +62,12 @@ def __str__(self) -> str:
|
51 | 62 | ASSIGNMENT: Final[ErrorCode] = ErrorCode(
|
52 | 63 | "assignment", "Check that assigned value is compatible with target", "General"
|
53 | 64 | )
|
| 65 | +METHOD_ASSIGN: Final[ErrorCode] = ErrorCode( |
| 66 | + "method-assign", |
| 67 | + "Check that assignment target is not a method", |
| 68 | + "General", |
| 69 | + sub_code_of=ASSIGNMENT, |
| 70 | +) |
54 | 71 | TYPE_ARG: Final = ErrorCode("type-arg", "Check that generic type arguments are present", "General")
|
55 | 72 | TYPE_VAR: Final = ErrorCode("type-var", "Check that type variable values are valid", "General")
|
56 | 73 | UNION_ATTR: Final = ErrorCode(
|
|
0 commit comments