Import resolution incorrectly falls back to relative package

オープン
#5,467 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python, rust
領域
compilers

調査の方向性

Reproduce with the given Python layout (b/a/code.py importing a). Locate Pyrefly's import resolution code in the Rust source; the issue names no files. Done means Pyrefly reports a missing package error instead of silently treating a as b.a.

索引モデルが issue の本文から書いたものです。

説明

Describe the Bug

This is without a pyrefly.toml file. Adding one "resolves" the issue w.r.t. this minimal example (though that's not always an option) due to the inferred root directory afaict. In the non-minimal example that I made this example from, adding a pyrefly.toml doesn' fix things, and it doesn't seem like fiddling with the config options helps either? It seems to prefer the definitely invalid self-package-import over the (possibly invalid) external import

Assuming you have the following package b with inner package b.a:

├── b
│   ├── a
│   │   ├── code.py
│   │   └── __init__.py
│   └── __init__.py

and the contents of code.py are:

from a import A

print(A())

And a cannot be found anywhere else, Pyrefly assumes a is b.a. This assumption is incorrect and differs from Python's actual behavior. To access b.a, the import would need to be from ..a import A.

Because pyrefly behaves the way it does, it will offer suggestions from b.a and won't report an error. When trying to run a file that depends on b, it will (if a is actually undiscoverable) hit an import error. If a is discoverable, it will almost certainly error out or behave unexpectedly due to the runtime import not matching the suggestions pyrefly was providing.

In this circumstance, a "did you mean..." lint + a "can't find this package" error is preferable. I don't think there's a case where a package can internally refer to itself. Even without a pyrefly.toml, it seems pretty obvious what the package structure is just from the directory tree, so the a in the current directory shouldn't be valid to import from any file within ./a/.

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

主要言語
Rust
スター
7.2k
フォーク
578
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

facebook/pyrefly のほかの issue

facebook/pyrefly の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。