Return failing source code.
(
self, astcache: Optional[Dict[Union[str, Path], ast.AST]] = None
)
| 242 | return self.frame.code.firstlineno |
| 243 | |
| 244 | def getsource( |
| 245 | self, astcache: Optional[Dict[Union[str, Path], ast.AST]] = None |
| 246 | ) -> Optional["Source"]: |
| 247 | """Return failing source code.""" |
| 248 | # we use the passed in astcache to not reparse asttrees |
| 249 | # within exception info printing |
| 250 | source = self.frame.code.fullsource |
| 251 | if source is None: |
| 252 | return None |
| 253 | key = astnode = None |
| 254 | if astcache is not None: |
| 255 | key = self.frame.code.path |
| 256 | if key is not None: |
| 257 | astnode = astcache.get(key, None) |
| 258 | start = self.getfirstlinesource() |
| 259 | try: |
| 260 | astnode, _, end = getstatementrange_ast( |
| 261 | self.lineno, source, astnode=astnode |
| 262 | ) |
| 263 | except SyntaxError: |
| 264 | end = self.lineno + 1 |
| 265 | else: |
| 266 | if key is not None and astcache is not None: |
| 267 | astcache[key] = astnode |
| 268 | return source[start:end] |
| 269 | |
| 270 | source = property(getsource) |
| 271 |