Skip to content

Relative imports fail outside the import root once a config exists (leading dot is dropped) #5594

Open

Description

@MarcoGorelli

Describe the Bug

I can't provide a sandbox for this, as it relies on multiple files, but here's how to reproduce it:

pyproject.toml
src/mypkg/__init__.py
tests/__init__.py
tests/test_b.py         :  from .sub.helpers import X
tests/sub/__init__.py
tests/sub/helpers.py    :  X = 1
tests/sub/test_a.py     :  from .helpers import X

In pyproject.toml there's:

[project]
name = "mypkg"
version = "0"

[tool.pyrefly]
project-includes = ["src", "tests"]

Then:

$ pyrefly check
ERROR tests/sub/test_a.py:1:1-23: Cannot find module `helpers` [missing-import]
ERROR tests/test_b.py:1:1-27: Cannot find module `sub.helpers` [missing-import]

Spotted in packaging

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions