Message404988
I've been thinking that perhaps it makes sense to special case printing of `self` argument in `__init__` methods. The same exact issue happens with PDB `args` command in `__init__` methods.
My idea is that in the __init__, you generally don't want to print `self` arg and trying to do so can cause this type of unexpected errors.
The reason is that __repr__ is not designed to be used for objects with unfinished initialization, because even if it doesn't break, it will give you incomplete or even misleading representation.
In case when __init__ has some complex logic that can raise an exception, it's likely that other local variables will help you identify the object. If there is no complex logic or other arguments, and __init__ still failed, you can say that there wasn't yet an actual object that can be uniquely represented.
Therefore I think it makes sense to simply omit representing `self` arg (or first arg of the method) in both `StackSummary.extract()` and PDB `args` command. It may break some existing code but I think it would be a small amount of code affected. Because of this it can only go into 3.11 version. I feel like on the balance it would be a good change to make, but I'm curious to hear other opinions. |
|
Date |
User |
Action |
Args |
2021-10-25 18:10:45 | andrei.avk | set | recipients:
+ andrei.avk, serhiy.storchaka, iritkatriel, moi90, kj, jbw |
2021-10-25 18:10:45 | andrei.avk | set | messageid: <1635185445.69.0.518241290693.issue43656@roundup.psfhosted.org> |
2021-10-25 18:10:45 | andrei.avk | link | issue43656 messages |
2021-10-25 18:10:45 | andrei.avk | create | |
|