Repository navigation
[pyrefly] Diagnose directory-relative imports - #4905
WilliamK112 wants to merge 4 commits into
Conversation
Imports that resolve only through the directory-relative fallback can work when a file is run directly but fail when it is loaded as part of a package. Attach a typed, non-fatal diagnostic at that narrow resolver boundary while preserving normal search precedence and keeping explicit fallback roots silent. Map the BasedPyright compatibility rule to the new error kind, document it, and cover resolver, configuration, and end-to-end behavior. Signed-off-by: Ching-Wei Kang <ckang53@wisc.edu>
|
This pull request has been imported. If you are a Meta employee, you can view this in D119718772. (Because this pull request was imported automatically, there will not be any future comments.) |
This comment has been minimized.
This comment has been minimized.
kinto0
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
|
looks great to me, but I wonder if this should default to "ignore" instead of "warn". cc @connernilsen for opinions |
This comment has been minimized.
This comment has been minimized.
connernilsen
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
…tive-import-4174-review # Conflicts: # pyrefly/lib/test/state.rs
|
Addressed both review threads and rebased the implementation onto current upstream
All targeted tests, documentation consistency tests, formatting, Clippy, and extension tests pass. I also ran the full 9,078-test library suite: 9,072 passed and 3 were ignored. The remaining 3 host-sensitive LSP tests fail locally because interpreter discovery selects Ready for another look when convenient. |
This comment has been minimized.
This comment has been minimized.
|
thanks! I think the last remaining item is to default to "warn" instead of "ignore" |
|
@kinto0 Addressed the last item on head Validation:
All passed. Ready for another look when convenient. |
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Summary
Add a dedicated
directory-relative-importdiagnostic when an unqualified import resolves only throughFallbackSearchPath::DirectoryRelative.The diagnostic is a non-fatal warning by default, so the module continues to resolve while users get guidance that first emphasizes missing or misconfigured search paths and site package paths, then explicit relative or fully qualified imports. BasedPyright
reportImplicitRelativeImportmigration keeps the existingmissing-importmapping and additionally configures the dedicated error kind.The branch is merged with current upstream
main, uses the currentFindImportOptionsAPI, and covers directory-relative fallback, explicit fallback, configured search-path precedence, end-to-end diagnostic reporting, configuration migration, generated presets, and documentation.Fixes #4174
Test Plan
cargo fmt --all -- --checkcargo test -p pyrefly_config test_implicit_relative_import_maps_to_import_error_kindscargo test -p pyrefly_config test_doc_headerscargo test -p pyrefly_config test_doc_severitiescargo test -p pyrefly_config test_error_presets_jsoncargo test -p pyrefly test_directory_relative_import_emits_dedicated_diagnosticcargo test -p pyrefly test_directory_relative_fallback_reports_directory_relative_importcargo test -p pyrefly test_explicit_fallback_does_not_report_directory_relative_importcargo test -p pyrefly test_absolute_search_path_precedes_directory_relative_fallbackpython3 test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema