-
-
Notifications
You must be signed in to change notification settings - Fork 652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
handle Python concatenated strings in Rust dependency inference parser #22050
base: main
Are you sure you want to change the base?
handle Python concatenated strings in Rust dependency inference parser #22050
Conversation
self.code_at(range) | ||
.trim_start_matches(|c| "rRuUfFbB".contains(c)) | ||
.trim_matches(|c| "'\"".contains(c)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on your comments, I think you handled the r"..."
, u"..."
, f"..."
, and b"..."
based on the nodes in a concatenated string, right? Or at least f-strings.
What about excluding strings that have quote marks? Are you relying on the python-side post processing with isidentifier()
to exclude that?
if !text.contains(|c: char| c.is_ascii_whitespace() || c == '\\') | ||
&& !self.is_pragma_ignored_recursive(node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be the place to exclude strings with quote marks or any other expressions we might want to add on the rust side. (See my other comment) Right?
As reported in #20324, the Rust-based Python import parser does not handle certain valid source patterns including concatenated strings.
Fix the Rust-based parser to handle concatenated strings correctly. Strings are parsed out of
Node
s via the newextract_string
helper. Theinsert_import
function is refactored to avoid double parsing of strings.Added some tests as well for concatenated strings.