| 668 | |
| 669 | |
| 670 | class PropertyStubsGenerator(StubsGenerator): |
| 671 | def __init__(self, name, prop, module_name): |
| 672 | self.name = name |
| 673 | self.prop = prop |
| 674 | self.module_name = module_name |
| 675 | self.signature = None # type: PropertySignature |
| 676 | |
| 677 | def parse(self): |
| 678 | self.signature = self.property_signature_from_docstring( |
| 679 | self.prop, self.module_name |
| 680 | ) |
| 681 | |
| 682 | def to_lines(self): # type: () -> List[str] |
| 683 | |
| 684 | docstring = self.sanitize_docstring(self.prop.__doc__) |
| 685 | docstring_prop = "\n\n".join( |
| 686 | [docstring, ":type: {rtype}".format(rtype=self.signature.rtype)] |
| 687 | ) |
| 688 | |
| 689 | result = [ |
| 690 | "@property", |
| 691 | "def {field_name}(self) -> {rtype}:".format( |
| 692 | field_name=self.name, rtype=self.signature.rtype |
| 693 | ), |
| 694 | self.format_docstring(docstring_prop), |
| 695 | ] |
| 696 | |
| 697 | if self.signature.setter_args != "None": |
| 698 | result.append("@{field_name}.setter".format(field_name=self.name)) |
| 699 | result.append( |
| 700 | "def {field_name}({args}) -> None:".format( |
| 701 | field_name=self.name, args=self.signature.setter_args |
| 702 | ) |
| 703 | ) |
| 704 | if docstring: |
| 705 | result.append(self.format_docstring(docstring)) |
| 706 | else: |
| 707 | result.append(self.indent("pass")) |
| 708 | |
| 709 | return result |
| 710 | |
| 711 | |
| 712 | class ClassStubsGenerator(StubsGenerator): |