Returns a description of the error. :param concise: Whether to return a concise, one-line description
(self, concise: bool = False)
| 152 | return self.message.endswith('Maybe mark it as "@type_check_only"?') |
| 153 | |
| 154 | def get_description(self, concise: bool = False) -> str: |
| 155 | """Returns a description of the error. |
| 156 | |
| 157 | :param concise: Whether to return a concise, one-line description |
| 158 | |
| 159 | """ |
| 160 | if concise: |
| 161 | return _style(self.object_desc, bold=True) + " " + self.message |
| 162 | |
| 163 | stub_line = None |
| 164 | stub_file = None |
| 165 | if not isinstance(self.stub_object, Missing): |
| 166 | stub_line = self.stub_object.line |
| 167 | stub_node = get_stub(self.object_path[0]) |
| 168 | if stub_node is not None: |
| 169 | stub_file = stub_node.path or None |
| 170 | |
| 171 | stub_loc_str = "" |
| 172 | if stub_file: |
| 173 | stub_loc_str += f" in file {Path(stub_file)}" |
| 174 | if stub_line: |
| 175 | stub_loc_str += f"{':' if stub_file else ' at line '}{stub_line}" |
| 176 | |
| 177 | runtime_line = None |
| 178 | runtime_file = None |
| 179 | if not isinstance(self.runtime_object, Missing): |
| 180 | try: |
| 181 | runtime_line = inspect.getsourcelines(self.runtime_object)[1] |
| 182 | except (OSError, TypeError, SyntaxError): |
| 183 | pass |
| 184 | try: |
| 185 | runtime_file = inspect.getsourcefile(self.runtime_object) |
| 186 | except TypeError: |
| 187 | pass |
| 188 | |
| 189 | runtime_loc_str = "" |
| 190 | if runtime_file: |
| 191 | runtime_loc_str += f" in file {Path(runtime_file)}" |
| 192 | if runtime_line: |
| 193 | runtime_loc_str += f"{':' if runtime_file else ' at line '}{runtime_line}" |
| 194 | |
| 195 | output = [ |
| 196 | _style("error: ", color="red", bold=True), |
| 197 | _style(self.object_desc, bold=True), |
| 198 | " ", |
| 199 | self.message, |
| 200 | "\n", |
| 201 | "Stub:", |
| 202 | _style(stub_loc_str, dim=True), |
| 203 | "\n", |
| 204 | _style(self.stub_desc + "\n", color="blue", dim=True), |
| 205 | "Runtime:", |
| 206 | _style(runtime_loc_str, dim=True), |
| 207 | "\n", |
| 208 | _style(self.runtime_desc + "\n", color="blue", dim=True), |
| 209 | ] |
| 210 | return "".join(output) |
| 211 |
no test coverage detected