facebook / facebook/pyrefly

Add a diagnostic for implicit relative imports

Open
#4,174 3 comments 0 reactions 1 assignee Claimed by @WilliamK112 View on GitHub
help wanted typechecking
Dominant language
Rust
Stars
7k
Forks
516
PR merge metrics
No merged PRs in 30d

Description

## Summary

Add detection of implicit relative imports equivalent to Basedpyright's `reportImplicitRelativeImport` rule.

Documentation:

https://docs.basedpyright.com/latest/benefits-over-pyright/new-diagnostic-rules/#reportimplicitrelativeimport

## Existing Pyrefly handling

Pyrefly recognizes `reportImplicitRelativeImport` while migrating Pyright
configuration and maps it to `missing-import`:

https://github.com/facebook/pyrefly/commit/46dacddf84499d36562d0d9f71fad5893e7948e4

This issue is for first-class detection of the more specific implicit-relative-
import condition rather than treating it solely as a general missing import.

## Desired behavior

- Detect an unqualified import that cannot be resolved through the normal absolute import roots but resolves only by searching from the importing file’s directory upward toward the configured execution root.
- Explain that the import may fail when the file is imported as part of a package.
- Suggest either an explicit relative import or the full absolute package path.
- Do not report imports that resolve normally through configured import roots, search paths, the standard library, or installed packages.
- Provide a dedicated, independently configurable diagnostic such as implicit-relative-import.
- Define an appropriate default severity; Basedpyright enables the equivalent diagnostic as an error in its default recommended mode.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.