Skip to content

Conversation

Renkai
Copy link
Contributor

@Renkai Renkai commented Aug 22, 2025

@Renkai Renkai marked this pull request as draft August 22, 2025 07:58
@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Aug 22, 2025
Copy link
Contributor

github-actions bot commented Aug 22, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@AlexWaygood AlexWaygood changed the title [WIP] Add search paths info to unresolved import diagnostics [ty] [WIP] Add search paths info to unresolved import diagnostics Aug 22, 2025
Copy link
Contributor

github-actions bot commented Aug 22, 2025

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

@Renkai Renkai changed the title [ty] [WIP] Add search paths info to unresolved import diagnostics [ty] Add search paths info to unresolved import diagnostics Aug 22, 2025
@Renkai
Copy link
Contributor Author

Renkai commented Aug 22, 2025

This solution called search_paths again to show the paths, not sure if carry the original results here is a better way, that way seems need changes in many places.

@Renkai Renkai marked this pull request as ready for review August 22, 2025 08:28
@Renkai Renkai requested a review from MichaReiser as a code owner August 22, 2025 08:58
@AlexWaygood AlexWaygood added the diagnostics Related to reporting of diagnostics. label Aug 22, 2025
@carljm carljm removed their request for review August 22, 2025 18:41
@carljm
Copy link
Contributor

carljm commented Aug 22, 2025

Thanks for working on this!

@AlexWaygood can you take the lead on review here?

@AlexWaygood
Copy link
Member

Sure

@AlexWaygood AlexWaygood self-assigned this Aug 22, 2025
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks great! I pushed a few minor tweaks to the PR.

It would be great to add a few more integration tests that have extra-paths set and/or an editable install.

Comment on lines +709 to +715
SearchPathInner::Extra(_) => {
"extra search path specified on the CLI or in your config file"
}
SearchPathInner::FirstParty(_) => "first-party code",
SearchPathInner::StandardLibraryCustom(_) => {
"custom stdlib stubs specified on the CLI or in your config file"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally I feel like we'd be able to tell the user whether it was a CLI option or a config-file setting that caused us to look at an extra search path (or a custom stdlib search paths) during module resolution. But that would involve a fair bit of refactoring probably; I think it's best to leave it out of this PR.

@AlexWaygood AlexWaygood requested a review from BurntSushi August 25, 2025 16:41
@Renkai Renkai requested a review from BurntSushi August 26, 2025 02:09
Copy link
Member

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one minor nit and passing CI.

// Add search paths information to the diagnostic
// Use the same search paths function that is used in actual module resolution
let search_paths: Vec<_> =
search_paths(self.db(), ModuleResolveMode::StubsAllowed).collect();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why collect all the search paths into memory first? It seems a little gratuitous. You could do let search_paths = search_paths(..).peekable(); and then if search_paths.peek().is_some() { and for (index, path) in search_paths.enumerate() { below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated by peekable. It seems requires more review to trigger next CI test. But the test looks fine on my computer now.

@BurntSushi BurntSushi merged commit 73720c7 into astral-sh:main Aug 26, 2025
38 checks passed
@BurntSushi
Copy link
Member

Thank you!!!

carljm added a commit to leandrobbraga/ruff that referenced this pull request Aug 27, 2025
* main:
  [`ruff`] Preserve relative whitespace in multi-line expressions (`RUF033`) (astral-sh#19647)
  [ty] Optimize TDD atom ordering (astral-sh#20098)
  [`airflow`] Extend `AIR311` and `AIR312` rules (astral-sh#20082)
  [ty] Preserve qualifiers when accessing attributes on unions/intersections (astral-sh#20114)
  [ty] Fix the inferred interface of specialized generic protocols (astral-sh#19866)
  [ty] Infer slightly more precise types for comprehensions (astral-sh#20111)
  [ty] Add more tests for protocols (astral-sh#20095)
  [ty] don't eagerly unpack aliases in user-authored unions (astral-sh#20055)
  [`flake8-use-pathlib`] Update links to the table showing the correspondence between `os` and `pathlib` (astral-sh#20103)
  [`flake8-use-pathlib`] Make `PTH100` fix unsafe because it can change behavior (astral-sh#20100)
  [`flake8-use-pathlib`] Delete unused `Rule::OsSymlink` enabled check (astral-sh#20099)
  [ty] Add search paths info to unresolved import diagnostics (astral-sh#20040)
  [`flake8-logging-format`] Add auto-fix for f-string logging calls (`G004`) (astral-sh#19303)
  Add a `ScopeKind` for the `__class__` cell (astral-sh#20048)
  Fix incorrect D413 links in docstrings convention FAQ (astral-sh#20089)
  [ty] Refactor inlay hints structure to use separate parts (astral-sh#20052)
second-ed pushed a commit to second-ed/ruff that referenced this pull request Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diagnostics Related to reporting of diagnostics. ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve hint for unresolved-import diagnostic

4 participants