Format filename lines with custom formatting from caching compiler or `File *.py` by default Parameters ---------- em: wether bold or not file : str
(
em: bool,
file: str | None,
*,
lineno: int | None = None,
)
| 167 | |
| 168 | |
| 169 | def _tokens_filename( |
| 170 | em: bool, |
| 171 | file: str | None, |
| 172 | *, |
| 173 | lineno: int | None = None, |
| 174 | ) -> TokenStream: |
| 175 | """ |
| 176 | Format filename lines with custom formatting from caching compiler or `File *.py` by default |
| 177 | |
| 178 | Parameters |
| 179 | ---------- |
| 180 | em: wether bold or not |
| 181 | file : str |
| 182 | """ |
| 183 | Normal = Token.NormalEm if em else Token.Normal |
| 184 | Filename = Token.FilenameEm if em else Token.Filename |
| 185 | ipinst = get_ipython() |
| 186 | if ( |
| 187 | ipinst is not None |
| 188 | and (data := ipinst.compile.format_code_name(file)) is not None |
| 189 | ): |
| 190 | label, name = data |
| 191 | if lineno is None: |
| 192 | return [ |
| 193 | (Normal, label), |
| 194 | (Normal, " "), |
| 195 | (Filename, name), |
| 196 | ] |
| 197 | else: |
| 198 | return [ |
| 199 | (Normal, label), |
| 200 | (Normal, " "), |
| 201 | (Filename, name), |
| 202 | (Filename, f", line {lineno}"), |
| 203 | ] |
| 204 | else: |
| 205 | name = util_path.compress_user( |
| 206 | py3compat.cast_unicode(file or "", util_path.fs_encoding) |
| 207 | ) |
| 208 | if lineno is None: |
| 209 | return [ |
| 210 | (Normal, "File "), |
| 211 | (Filename, name), |
| 212 | ] |
| 213 | else: |
| 214 | return [ |
| 215 | (Normal, "File "), |
| 216 | (Filename, f"{name}:{lineno}"), |
| 217 | ] |
| 218 | |
| 219 | |
| 220 | def _simple_format_traceback_lines( |
no test coverage detected
searching dependent graphs…