(
self,
indent: str = "",
is_async: bool = False,
any_val: str | None = None,
docstring: str | None = None,
include_docstrings: bool = False,
)
| 105 | return self.has_catchall_args() and self.ret_type in (None, "Any", "typing.Any") |
| 106 | |
| 107 | def format_sig( |
| 108 | self, |
| 109 | indent: str = "", |
| 110 | is_async: bool = False, |
| 111 | any_val: str | None = None, |
| 112 | docstring: str | None = None, |
| 113 | include_docstrings: bool = False, |
| 114 | ) -> str: |
| 115 | args: list[str] = [] |
| 116 | for arg in self.args: |
| 117 | arg_def = arg.name |
| 118 | |
| 119 | if arg_def in keyword.kwlist: |
| 120 | arg_def = "_" + arg_def |
| 121 | |
| 122 | if ( |
| 123 | arg.type is None |
| 124 | and any_val is not None |
| 125 | and arg.name not in ("self", "cls") |
| 126 | and not arg.name.startswith("*") |
| 127 | ): |
| 128 | arg_type: str | None = any_val |
| 129 | else: |
| 130 | arg_type = arg.type |
| 131 | if arg_type: |
| 132 | arg_def += ": " + arg_type |
| 133 | if arg.default: |
| 134 | arg_def += f" = {arg.default_value}" |
| 135 | |
| 136 | elif arg.default: |
| 137 | arg_def += f"={arg.default_value}" |
| 138 | |
| 139 | args.append(arg_def) |
| 140 | |
| 141 | retfield = "" |
| 142 | ret_type = self.ret_type if self.ret_type else any_val |
| 143 | if ret_type is not None: |
| 144 | retfield = " -> " + ret_type |
| 145 | |
| 146 | prefix = "async " if is_async else "" |
| 147 | sig = f"{indent}{prefix}def {self.name}{self.type_args}({', '.join(args)}){retfield}:" |
| 148 | # if this object has a docstring it's probably produced by a SignatureGenerator, so it |
| 149 | # takes precedence over the passed docstring, which acts as a fallback. |
| 150 | doc = (self.docstring or docstring) if include_docstrings else None |
| 151 | if doc: |
| 152 | suffix = f"\n{indent} {mypy.util.quote_docstring(doc)}" |
| 153 | else: |
| 154 | suffix = " ..." |
| 155 | return f"{sig}{suffix}" |
| 156 | |
| 157 | |
| 158 | # States of the docstring parser. |
no test coverage detected