Fix: get_parso_cache_node() in jedi/parser_utils.py performs an unguarded... - #2105
Closed
M001N wants to merge 1 commit into
Closed
Fix: get_parso_cache_node() in jedi/parser_utils.py performs an unguarded...#2105M001N wants to merge 1 commit into
M001N wants to merge 1 commit into
Conversation
get_parso_cache_node() does a raw dict lookup into parso's internal parser_cache. That cache is only reliably populated when diff_cache is enabled, and jedi passes diff_cache=settings.fast_parser when parsing. With fast_parser=False, completing an unsaved file (path='') could hit a KeyError deep in jedi's caching-optimization code. Wrap the lookup in try/except KeyError and fall back to self._parso_cache_node = None, mirroring the existing fallback used one branch above for the analogous path is None case. Fixes davidhalter#1888
Owner
|
For the love of god, please disclose that this was done with AI!!! Hi, I'm sorry to say this, but I decided to not work at all with AI generated pull requests/content. There are multiple reasons for this:
Thank you anyway for trying to contribute to Open Source. I would really appreciate if you avoid the usage of LLMs in my projects. It is obviously fine to use LLMs as a search/brainstorming tool with my projects, just don't use it to interact with me. PS: As a side note I want to mention that I'm probably not the only maintainer that has a difficult relationship with LLM content. So you probably should ask first before you use LLMs for other repositories. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Wrapped the get_parso_cache_node(...) call in jedi/inference/filters.py's _AbstractUsedNamesFilter.init in a try/except KeyError, falling back to self._parso_cache_node = None, mirroring the existing fallback used for the path is None branch.
Problem
davidhalter/jedi issue reference: #1888
Root Cause
get_parso_cache_node() in jedi/parser_utils.py performs an unguarded dict lookup into parso's internal parser_cache. That cache is only reliably populated for a path when diff_cache is enabled during parsing, but jedi passes diff_cache=settings.fast_parser (jedi/api/init.py, jedi/inference/imports.py). With fast_parser=False, the cache entry for an unsaved file's path may never exist, so the lookup raises KeyError. The same init in jedi/inference/filters.py already treats a missing/unavailable cache node as an expected, handled case one branch above (path is None -> self._parso_cache_node = None), confirming the rest of the class tolerates a None cache node.
Testing
PASS - all 3 tests passed (2 existing test_cache.py tests + new regression test); reproduced the KeyError crash pre-fix and confirmed it no longer occurs post-fix.
Related Issue
#1888