Message360670
Given
(1) instantiation of an enumeration class with an invalid value
(2) a try/except around the instantiation where the exception is ignored
Then:
An unneeded reference to the bad value is lost (as well as other values that I suspect are local variables within a participating method)
When run, the attached sample script shows before and after reference counts which demonstrate the potential resource leaks. The sample script includes the output from running the script on Python version 3.7.5 within the module docstring.
The root cause appears to be in the exception handling in the Enum.__new__ method (in the area where it calls the _missing_ hook). The attached sample script includes a simplified version of those methods that should help pinpoint the code in question and confirm the root cause.
Not being an exception nitty-gritty expert, I have suspicions that users should be warned about using this pattern of exception handling. I suspect this pattern would be worth avoiding in the Enum implementation.
I am willing to take a stab at submitting a patch for Enum. I hesitate slightly not knowing if there are specific reasons for the code existing in its current form. Alternatively, I plan on being at PyCon2020 for the sprints and could be available then to work on it. |
|
Date |
User |
Action |
Args |
2020-01-25 06:30:33 | dan.gass@gmail.com | set | recipients:
+ dan.gass@gmail.com |
2020-01-25 06:30:33 | dan.gass@gmail.com | set | messageid: <1579933833.85.0.945475764886.issue39451@roundup.psfhosted.org> |
2020-01-25 06:30:33 | dan.gass@gmail.com | link | issue39451 messages |
2020-01-25 06:30:33 | dan.gass@gmail.com | create | |
|