[New-bugs-announce] [issue43656] StackSummary.format fails if str(value) fails

Martin report at bugs.python.org
Mon Mar 29 05:36:49 EDT 2021


New submission from Martin <martin.schroeder at nerdluecht.de>:

With `capture_locals=True`, `StackSummary.format` prints the local variables for every frame:
https://github.com/python/cpython/blob/4827483f47906fecee6b5d9097df2a69a293a85c/Lib/traceback.py#L440

This will fail, however, if string conversion fails.

StackSummary.format should be robust towards such possibilities.


An easy fix would be a utility function:

```
def try_str(x):
  try:
    return str(x)
  except:
    return "<some sensible hint>"
```

----------
messages: 389679
nosy: moi90
priority: normal
severity: normal
status: open
title: StackSummary.format fails if str(value) fails
type: enhancement
versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43656>
_______________________________________


More information about the New-bugs-announce mailing list