FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

linecache should remember files it failed to read and not try again · Issue #94436 · python/cpython · GitHub

Repository navigation

linecache should remember files it failed to read and not try again #94436

Open

Description

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.

Linked PRs

Activity

  1. self-assigned this
    on Jun 30, 2022
  2. iritkatriel commented on Jun 30, 2022

    MemberAuthor
  3. removed their assignment
    on Sep 3, 2022
  4. corona10 commented on Oct 3, 2022

    Member

    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

  5. iritkatriel commented on Oct 3, 2022

    MemberAuthor

    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.

  6. vstinner commented on Oct 3, 2022

    Member

    We may need to understand the following decision that cache was removed for this case.

    Sorry, I don't recall the rationale for this change in Python 3.

    updatecache() changes:

    • commit 921c824 (1992, initial commit adding Lib/linecache.py): except IOError: (...) return []
    • commit c341c62 (1992) iterates on sys.path and return [] if the file is not found
    • commit aada7b8 (2010) adds except IOError: pass -- introduce a BUG! lines doesn't exist in this case (NameError)
    • commit 78f43a7 (2010) replaces pass with lines = [] -- fix the NameError
    • commit 41a64a5 (2010) replaces lines = [] with return []
  7. vstinner commented on Oct 3, 2022

    Member

    We should instead cache the negative lookup result and bypass the search in future queries.

    It sounds reasonable to me.

  8. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixesperformancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directory

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL