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