Optimize type checking range lookup with binary search#7
Open
DebanKsahu wants to merge 4 commits into
Open
Conversation
…ith binary search Now `_find_type_checking_ranges()` will return a range array sorted by start line, and the lineno for any import node will be matched using binary search with the help of the `bisect` library for faster lookup. Currently, this assumes that there are no overlapping ranges in the ranges array. Overlapping ranges can occur only when there are nested `if TYPE_CHECKING:` blocks.
Use `isinstance()` to ensure `node.lineno` is an integer before checking TYPE_CHECKING ranges. This avoids returning `Any` from `_in_type_checking()` and fixes the mypy `no-any-return` error.
Replaced the inline normalization of file paths with a precomputed set to improve performance and reduce redundant computations during graph extraction.
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.
Pull Request
Key changes include:
Functional Improvements:
bisect_rightfor efficient range lookup in_in_type_checking, enhancing both correctness and performance.Code Style and Readability:
ruff formatandruff check --fixChange Type