-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathtext_choices.py
70 lines (56 loc) · 2.08 KB
/
text_choices.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from astroid import MANAGER, scoped_nodes, nodes, inference_tip
from pylint_django import utils
class_names = set()
def is_tuple_in_text_choices(node):
# file_name = node.root().file
# if file_name not in file_names:
# file_names.update({file_name})
# import ipdb; ipdb.set_trace()
# else:
# return False
if not (isinstance(node.parent, nodes.Assign)
or isinstance(node.parent, nodes.FunctionDef)) :
return False
if not isinstance(node.parent.parent, nodes.ClassDef):
return False
if "TextChoices" in [i.name for i in node.parent.parent.bases]:
import ipdb; ipdb.set_trace()
class_name = node.parent.parent.name
if class_name not in class_names:
class_names.update({class_name})
# import ipdb; ipdb.set_trace()
else:
return False
# if node.parent.parent.name == "SomeTextChoices":
# import ipdb; ipdb.set_trace()
# else:
# return False
# if node.parent.parent.parent.name in ["TextChoices", "SomeClass", "ChoicesMeta", "TextChoices"]:
# import ipdb; ipdb.set_trace()
# else:
# return False
# if node.root().file.endswith("enums.py"):
# import ipdb; ipdb.set_trace()
# else:
# return False
# try:
# if node.root().file.endswith("model_enum.py"):
# import ipdb; ipdb.set_trace()
# except:
# import ipdb; ipdb.set_trace()
# if (node.parent.parent.name != "LazyObject"
# and node.parent.parent.parent.name != "django.db.models.expressions"
# and node.parent.parent.parent.name != "django.db.models.fields"):
# import ipdb; ipdb.set_trace()
if isinstance(node.func, nodes.Attribute):
attr = node.func.attrname
elif isinstance(node.func, nodes.Name):
attr = node.func.name
else:
return False
return True
def infer_key_classes(node, context=None):
pass
def add_transforms(manager):
manager.register_transform(nodes.Call, inference_tip(infer_key_classes),
is_tuple_in_text_choices)