Skip to content

Fix completions for import aliases#4111

Open
roian6 wants to merge 1 commit into
facebook:mainfrom
roian6:pyrefly-4107-suppress-import-alias-completions
Open

Fix completions for import aliases#4111
roian6 wants to merge 1 commit into
facebook:mainfrom
roian6:pyrefly-4107-suppress-import-alias-completions

Conversation

@roian6

@roian6 roian6 commented Jul 11, 2026

Copy link
Copy Markdown

Summary

Fixes #4107

Import alias names are local binding targets, but completion treated them as import paths. This produced module suggestions for import pandas as pd and package-export suggestions for from package import name as alias.

Detect when the cursor is on Alias.asname for either import form and return no completions before normal import completion dispatch. Normal module and imported-name completions remain unchanged outside alias targets. Lightweight regression tests cover both forms.

AI agent disclosure: This PR was prepared by Hermes Agent, an AI coding agent, under the contributor's direction. The agent traced the relevant source paths, added and exercised regression tests, ran the repository validation commands listed below, and performed an independent automated code review. The contributor is aware of the AI-agent involvement.

Test Plan

  • cargo test -p pyrefly import_alias_has_no_completions -- --nocapture — 2 passed, 0 failed
  • cargo test -p pyrefly 'test::lsp::completion::' — 100 passed, 0 failed
  • python3 test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema — formatting and linting passed
  • cargo fmt --all -- --check
  • git diff --check

Import aliases create local binding names, so treating them as import targets produces irrelevant module or export suggestions.

Detect alias ranges for both import forms before normal completion dispatch. Lightweight regression tests cover direct and from-import aliases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

import pandas as pd completes to import pandas as pdb

1 participant