Skip to content

Add a diagnostic for implicit relative imports #4174

Description

@TyceHerrman

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:

46dacdd

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions