When linecache doesn't find a source file or fails to read it due to OSError, SyntaxError or UnicodeDecodeError, it returns an empty result. In subsequent attempts it would try to find and read the file again.
We should instead cache the negative lookup result and bypass the search in future queries.
We may need to understand the following decision that cache was removed for this case. @vstinner, Is this different behavior from what @iritkatriel intended?
I have doubts about this issue as well. It came up in #94410 (comment), where it seemed to make sense, but I've seen other issues where we do/don't want various things cached, and I don't know if there's an obviously correct thing to do here.
Activity
iritkatriel commented on Jun 30, 2022
CC @gpshead .
corona10 commented on Oct 3, 2022
We may need to understand the following decision that cache was removed for this case.
@vstinner, Is this different behavior from what @iritkatriel intended?
41a64a5
iritkatriel commented on Oct 3, 2022
I have doubts about this issue as well. It came up in #94410 (comment), where it seemed to make sense, but I've seen other issues where we do/don't want various things cached, and I don't know if there's an obviously correct thing to do here.
vstinner commented on Oct 3, 2022
Sorry, I don't recall the rationale for this change in Python 3.
updatecache() changes:
vstinner commented on Oct 3, 2022
It sounds reasonable to me.