Skip to content
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 from foo import * wildcard imports in Rust dep inference parser (Cherry-pick of #19249) #19255

Merged
merged 1 commit into from
Jun 6, 2023

Conversation

WorkerPants
Copy link
Member

This fixes #19248 by implementing explicit handling for * wildcard imports in the Rust-based Python dependency inference parser.

The commits are somewhat individually reviewable:

  1. switching how the insert_import arguments are consumed from the syntax tree, for from ... import ... statements in particular:
    • before: name and module_name correspond to import $name, "$name", from $module_name import $name
    • after: base and imported correspond to import $base, "$base", from $base import $imported
    • This is in particular flipping the last one, and changes whether the from ... part is the optional arg (before) or not (after).
    • The motivation is that there's more functional similarities between the from ... part and a plain import ... statement, than between the import ... part and a plain import ... statement, despite the superficial similarities of it! (from foo import bar is a little like import foo as __secret; bar = __secret.bar.)
  2. Add some tests that fail
  3. Fix the bug
  4. (and others) some tweaks, including defence-in-depth against similar problems happening in future

…ser (#19249)

This fixes #19248 by implementing explicit handling for `*` wildcard
imports in the Rust-based Python dependency inference parser.

The commits are somewhat individually reviewable:

1. switching how the `insert_import` arguments are consumed from the
syntax tree, for `from ... import ...` statements in particular:
   - before: `name` and `module_name` correspond to `import $name`,
     `"$name"`, `from $module_name import $name`
   - after: `base` and `imported` correspond to `import $base`, `"$base"`,
     `from $base import $imported`
   - This is in particular flipping the last one, and changes whether the
     `from ...` part is the optional arg (before) or not (after).
   - The motivation is that there's more functional similarities between
     the `from ...` part and a plain `import ...` statement, than between the
     `import ...` part and a plain `import ...` statement, despite the
     superficial similarities of it! (`from foo import bar` is a little like
     `import foo as __secret; bar = __secret.bar`.)
2. Add some tests that fail
3. Fix the bug
4. (and others) some tweaks, including defence-in-depth against similar
    problems happening in future
@WorkerPants WorkerPants added this to the 2.17.x milestone Jun 6, 2023
@WorkerPants WorkerPants added the category:internal CI, fixes for not-yet-released features, etc. label Jun 6, 2023
@WorkerPants WorkerPants requested review from thejcannon and huonw June 6, 2023 01:19
@huonw huonw merged commit 562eb1f into 2.17.x Jun 6, 2023
@huonw huonw deleted the cherry-pick-19249-to-2.17.x branch June 6, 2023 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:internal CI, fixes for not-yet-released features, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants