Groups represent namespaces (classes and modules/files)
| 488 | |
| 489 | |
| 490 | class Group(): |
| 491 | """ |
| 492 | Groups represent namespaces (classes and modules/files) |
| 493 | """ |
| 494 | def __init__(self, token, group_type, display_type, import_tokens=None, |
| 495 | line_number=None, parent=None, inherits=None): |
| 496 | self.token = token |
| 497 | self.line_number = line_number |
| 498 | self.nodes = [] |
| 499 | self.root_node = None |
| 500 | self.subgroups = [] |
| 501 | self.parent = parent |
| 502 | self.group_type = group_type |
| 503 | self.display_type = display_type |
| 504 | self.import_tokens = import_tokens or [] |
| 505 | self.inherits = inherits or [] |
| 506 | assert group_type in GROUP_TYPE |
| 507 | |
| 508 | self.uid = "cluster_" + os.urandom(4).hex() # group doesn't work by syntax rules |
| 509 | |
| 510 | def __repr__(self): |
| 511 | return f"<Group token={self.token} type={self.display_type}>" |
| 512 | |
| 513 | def __lt__(self, other): |
| 514 | return self.label() < other.label() |
| 515 | |
| 516 | def label(self): |
| 517 | """ |
| 518 | Labels are what you see on the graph |
| 519 | :rtype: str |
| 520 | """ |
| 521 | return f"{self.display_type}: {self.token}" |
| 522 | |
| 523 | def filename(self): |
| 524 | """ |
| 525 | The ultimate filename of this group. |
| 526 | :rtype: str |
| 527 | """ |
| 528 | if self.group_type == GROUP_TYPE.FILE: |
| 529 | return self.token |
| 530 | return self.parent.filename() |
| 531 | |
| 532 | def add_subgroup(self, sg): |
| 533 | """ |
| 534 | Subgroups are found after initialization. This is how they are added. |
| 535 | :param sg Group: |
| 536 | """ |
| 537 | self.subgroups.append(sg) |
| 538 | |
| 539 | def add_node(self, node, is_root=False): |
| 540 | """ |
| 541 | Nodes are found after initialization. This is how they are added. |
| 542 | :param node Node: |
| 543 | :param is_root bool: |
| 544 | """ |
| 545 | self.nodes.append(node) |
| 546 | if is_root: |
| 547 | self.root_node = node |
no outgoing calls
no test coverage detected