Skip to content

fix Pyrefly inserted typing import in sub-optimal location #1490 - #1580

Closed
asukaminato0721 wants to merge 8 commits into
meta:mainfrom
asukaminato0721:1490
Closed

asukaminato0721 wants to merge 8 commits into
meta:mainfrom
asukaminato0721:1490

Conversation

@asukaminato0721

@asukaminato0721 asukaminato0721 commented Nov 14, 2025 •

Copy link
Copy Markdown
Collaborator

fixes #1490 fixes #3382

Adjusted so insert_import_edit* returns an ImportEdit with both the actual edit and a stable display string, and added logic to append new symbols to an existing matching from ... import ... statement instead of duplicating the import line. The helper now shares this richer info with callers so UI text stays human-readable.

Updated LSP code to consume the new struct, ensuring code-action titles and auto-import completion details still show from module import name while the actual edit mutates the existing line in place.

Taught the infer command to handle the new edit type and to skip empty/duplicate insertions when mutating files.

Revised the LSP code-action test to assert the merged-import behavior.

@meta-cla meta-cla Bot added the cla signed label Nov 14, 2025
@asukaminato0721
asukaminato0721 force-pushed the 1490 branch 2 times, most recently from df5401f to e3180ab Compare November 18, 2025 10:45
@asukaminato0721
asukaminato0721 marked this pull request as ready for review November 18, 2025 10:54
@asukaminato0721
asukaminato0721 marked this pull request as draft November 18, 2025 12:36
@meta-codesync

meta-codesync Bot commented Nov 20, 2025

Copy link
Copy Markdown
Contributor

@jvansch1 has imported this pull request. If you are a Meta employee, you can view this in D87254329.

@asukaminato0721
asukaminato0721 marked this pull request as ready for review November 21, 2025 11:57
Comment thread pyrefly/lib/test/lsp/completion.rs Resolved
Comment thread pyrefly/lib/state/ide.rs Resolved
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions github-actions Bot removed the stale label Jan 15, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot added the stale label Feb 2, 2026
@jvansch1

jvansch1 commented Feb 3, 2026

Copy link
Copy Markdown
Contributor

@asukaminato0721 Are you still planning to make changes to this PR? I see there are some failing checks.

@asukaminato0721
asukaminato0721 force-pushed the 1490 branch 2 times, most recently from b1b818e to 0e46400 Compare February 3, 2026 16:16
@asukaminato0721
asukaminato0721 marked this pull request as ready for review February 3, 2026 16:18
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copilot AI review requested due to automatic review settings February 11, 2026 18:25
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@codspeed

codspeed Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 35 untouched benchmarks
⏩ 9 skipped benchmarks1


Comparing asukaminato0721:1490 (733a067) with main (7573d4f)

Open in CodSpeed

Footnotes

  1. 9 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

5 similar comments
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@github-actions

Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Import-edit merging overlapped with autotype dry-run support and newer export-search results. Keep structured edits and follow-up unknown-name imports while ensuring dry runs remain non-mutating and report pending changes correctly.
@github-actions

Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@stroxler

Copy link
Copy Markdown
Contributor

Hey @asukaminato0721, I'm making a decision to cut this PR off not because it's necessarily bad, but for two reasons:

  • first, it probably needs to be split into multiple PRs, which makes keeping track of the original PR harder
  • second, this PR is so old that our processes don't work well - for example, there's a stale diff imported for it, which means auto-import doesn't work

Feel free to open a new PR or two covering this, I think we'll be able to turn it around much faster if you do.

If you decide to make a new PR, I have some notes to take into account. Note that one of the recommendations is to split this, it's got too much in it for a single PR:

P1 — Stale edit offsets corrupt imports (lines 475–493). Edits use the original AST after files have been rewritten. Reproduced from b import marker becoming from b import mar, MissingClassker, with exit code 0. Reparse or batch edits against one current snapshot.

P2 — Import controls are bypassed (lines 449–493). --imports=false still adds imports, while --dry-run can report no changes when write mode modifies the file.

P2 — Conflicting and duplicate imports (lines 464–493). Every export-search candidate is imported, silently shadowing alternatives. Repeated diagnostics also append the same symbol repeatedly.

P2 — User configuration is discarded (lines 453–460). The recheck uses CWD defaults instead of the resolved configuration. Reproduced importing a name explicitly suppressed by the supplied project config.

P2 — Deduplication suppresses necessary imports (lines 534–540). The display-string substring check mistakes from a import FooBar for an import of Foo, leaving an inferred annotation unresolved.

Recommendation: Keep the import-merging/LSP work, but split out the unknown-name repair pass. It is unrelated to the linked issues and adds a second cold check even on unchanged projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

6 participants