| 573 | |
| 574 | |
| 575 | class FreeFunctionStubsGenerator(StubsGenerator): |
| 576 | def __init__(self, name, free_function, module_name): |
| 577 | self.name = name |
| 578 | self.member = free_function |
| 579 | self.module_name = module_name |
| 580 | self.signatures = [] # type: List[FunctionSignature] |
| 581 | |
| 582 | def parse(self): |
| 583 | self.signatures = self.function_signatures_from_docstring( |
| 584 | self.name, self.member, self.module_name |
| 585 | ) |
| 586 | |
| 587 | def to_lines(self): # type: () -> List[str] |
| 588 | result = [] |
| 589 | docstring = self.sanitize_docstring(self.member.__doc__) |
| 590 | if not docstring and not ( |
| 591 | self.name.startswith("__") and self.name.endswith("__") |
| 592 | ): |
| 593 | logger.debug( |
| 594 | "Docstring is empty for '%s'" % self.fully_qualified_name(self.member) |
| 595 | ) |
| 596 | for sig in self.signatures: |
| 597 | if len(self.signatures) > 1: |
| 598 | result.append("@typing.overload") |
| 599 | result.append( |
| 600 | "def {name}({args}) -> {rtype}:".format( |
| 601 | name=sig.name, args=sig.args, rtype=sig.rtype |
| 602 | ) |
| 603 | ) |
| 604 | if docstring: |
| 605 | result.append(self.format_docstring(docstring)) |
| 606 | docstring = None # don't print docstring for other overloads |
| 607 | else: |
| 608 | result.append(self.indent("pass")) |
| 609 | |
| 610 | return result |
| 611 | |
| 612 | def get_involved_modules_names(self): # type: () -> Set[str] |
| 613 | involved_modules_names = set() |
| 614 | for s in self.signatures: # type: FunctionSignature |
| 615 | for t in s.get_all_involved_types(): # type: str |
| 616 | try: |
| 617 | module_name = t[: t.rindex(".")] |
| 618 | if self.is_valid_module(module_name): |
| 619 | involved_modules_names.add(module_name) |
| 620 | except ValueError: |
| 621 | pass |
| 622 | return involved_modules_names |
| 623 | |
| 624 | |
| 625 | class ClassMemberStubsGenerator(FreeFunctionStubsGenerator): |