|
4 | 4 | from collections.abc import Callable |
5 | 5 | from collections.abc import Iterable |
6 | 6 | from collections.abc import Sequence |
7 | | -from enum import Enum |
8 | 7 | from typing import Any |
9 | 8 | from typing import cast |
10 | 9 |
|
|
22 | 21 | NON_ESCAPE_SEQUENCE = re.compile(r"((?<!\\)[^\\]+)") |
23 | 22 |
|
24 | 23 |
|
25 | | -class MethodType(Enum): |
26 | | - """Type of method based on its decorator.""" |
27 | | - |
28 | | - STATICMETHOD = "staticmethod" |
29 | | - CLASSMETHOD = "classmethod" |
30 | | - INSTANCE = "instance" |
31 | | - |
32 | | - |
33 | | -def get_method_type(method: cst.FunctionDef) -> MethodType | None: |
34 | | - """Determine the method type based on decorators. |
35 | | -
|
36 | | - Returns: |
37 | | - MethodType.STATICMETHOD - for @staticmethod |
38 | | - MethodType.CLASSMETHOD - for @classmethod |
39 | | - MethodType.INSTANCE - for no decorators (regular instance method) |
40 | | - None - for other/multiple decorators (should be skipped) |
41 | | - """ |
42 | | - if not method.decorators: |
43 | | - return MethodType.INSTANCE |
44 | | - |
45 | | - if len(method.decorators) != 1: |
46 | | - # Multiple decorators - skip |
47 | | - return None |
48 | | - |
49 | | - decorator = method.decorators[0].decorator |
50 | | - if isinstance(decorator, cst.Name): |
51 | | - if decorator.value == "staticmethod": |
52 | | - return MethodType.STATICMETHOD |
53 | | - elif decorator.value == "classmethod": |
54 | | - return MethodType.CLASSMETHOD |
55 | | - |
56 | | - # Other decorator - skip |
57 | | - return None |
58 | | - |
59 | | - |
60 | 24 | def operator_number(node: cst.BaseNumber) -> Iterable[cst.BaseNumber]: |
61 | 25 | if isinstance(node, cst.Integer | cst.Float): |
62 | 26 | yield node.with_changes(value=repr(node.evaluated_value + 1)) |
|
0 commit comments