[pyrefly] Diagnose directory-relative imports - #4905
Open
WilliamK112 wants to merge 1 commit into
Open
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>
Contributor
|
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.) |
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a dedicated
implicit-relative-importdiagnostic when an unqualified import resolves only throughFallbackSearchPath::DirectoryRelative. Normal configured roots, build-system sources, typeshed, and site packages retain their existing precedence, while explicitly configured fallback roots remain silent.The diagnostic is a non-fatal warning by default, so the module continues to resolve while users get guidance to use an explicit relative import or the full absolute package path. This also maps BasedPyright
reportImplicitRelativeImportsettings to the dedicated error kind, updates the generated preset inventory and migration documentation, and covers resolver precedence plus end-to-end reporting.Fixes #4174
Test Plan
python3 test.py --no-test --no-conformance --no-jsonschemacargo test -p pyrefly_config -- --skip test_find_interpreter_precedence_venv(the skipped host-dependent test selects the globally installed/opt/anaconda3interpreter)cargo test -p pyrefly_config implicit_relativecargo test -p pyrefly_config test_error_presets_jsoncargo test -p pyrefly test::statecargo test -p pyrefly module::finder::tests::test_