msg295782 - (view) |
Author: Thomas Kluyver (takluyver) * |
Date: 2017-06-12 13:54 |
This came up in IPython & Jedi: several functions in inspect end up calling getfile(). If the object is something for which it can't find the source file, it throws an error, the message for which contains the object's repr. This is problematic for us because for some objects the repr may be expensive to calculate (e.g. data tables where the repr forms primary output, not just debugging information). In some cases, it could also throw another error. I plan to make a PR for this, but I'm opening an issue so I've got a bpo number. https://github.com/ipython/ipython/issues/10493 https://github.com/davidhalter/jedi/issues/919 |
|
|
msg295792 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2017-06-12 14:50 |
What is your proposed solution? This doesn't at the moment sound like a bug in Python to me. |
|
|
msg295796 - (view) |
Author: Thomas Kluyver (takluyver) * |
Date: 2017-06-12 15:36 |
Not exactly a bug, but I think that an improvement is possible. My plan is to delay computing the repr until the error is formatted, so that code which catches the TypeError can carry on safely. I think this is more relevant for inspect than for many other modules, because by design, we're often calling inspect functions on arbitrary objects which we can make few guarantees about. |
|
|
msg295807 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2017-06-12 17:50 |
I think in that case it is enough to report just type name. |
|
|
msg295808 - (view) |
Author: Thomas Kluyver (takluyver) * |
Date: 2017-06-12 17:54 |
Sure, I can do that if you want. The other thing I thought of was using object.__repr__, so the repr always shows like <foo object at 0x123abc...> . |
|
|
msg295809 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2017-06-12 17:56 |
The address of the object is not informative. The possibility of getting a source file is determined by the type of the object. |
|
|
msg295811 - (view) |
Author: Thomas Kluyver (takluyver) * |
Date: 2017-06-12 19:14 |
OK, I've updated the PR to do that. |
|
|
msg304903 - (view) |
Author: Yury Selivanov (yselivanov) *  |
Date: 2017-10-24 12:42 |
New changeset e968bc735794a7123f28f26d68fdf5dc8c845280 by Yury Selivanov (Thomas Kluyver) in branch 'master': bpo-30639: Lazily compute repr for error (#2132) https://github.com/python/cpython/commit/e968bc735794a7123f28f26d68fdf5dc8c845280 |
|
|
msg304905 - (view) |
Author: Yury Selivanov (yselivanov) *  |
Date: 2017-10-24 12:43 |
Thank you, Thomas. |
|
|