| 623 | |
| 624 | |
| 625 | class ClassMemberStubsGenerator(FreeFunctionStubsGenerator): |
| 626 | def __init__(self, name, free_function, module_name): |
| 627 | super(ClassMemberStubsGenerator, self).__init__( |
| 628 | name, free_function, module_name |
| 629 | ) |
| 630 | |
| 631 | def to_lines(self): # type: () -> List[str] |
| 632 | result = [] |
| 633 | docstring = self.sanitize_docstring(self.member.__doc__) |
| 634 | if not docstring and not ( |
| 635 | self.name.startswith("__") and self.name.endswith("__") |
| 636 | ): |
| 637 | logger.debug( |
| 638 | "Docstring is empty for '%s'" % self.fully_qualified_name(self.member) |
| 639 | ) |
| 640 | for sig in self.signatures: |
| 641 | args = sig.args |
| 642 | sargs = args.strip() |
| 643 | if not sargs.startswith("self"): |
| 644 | if sargs.startswith("cls"): |
| 645 | result.append("@classmethod") |
| 646 | # remove type of cls |
| 647 | args = ",".join(["cls"] + sig.split_arguments()[1:]) |
| 648 | else: |
| 649 | result.append("@staticmethod") |
| 650 | else: |
| 651 | # remove type of self |
| 652 | args = ",".join(["self"] + sig.split_arguments()[1:]) |
| 653 | if len(self.signatures) > 1: |
| 654 | result.append("@typing.overload") |
| 655 | |
| 656 | result.append( |
| 657 | "def {name}({args}) -> {rtype}: {ellipsis}".format( |
| 658 | name=sig.name, |
| 659 | args=args, |
| 660 | rtype=sig.rtype, |
| 661 | ellipsis="" if docstring else "...", |
| 662 | ) |
| 663 | ) |
| 664 | if docstring: |
| 665 | result.append(self.format_docstring(docstring)) |
| 666 | docstring = None # don't print docstring for other overloads |
| 667 | return result |
| 668 | |
| 669 | |
| 670 | class PropertyStubsGenerator(StubsGenerator): |