Import resolution incorrectly falls back to relative package
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 45/100
調査の方向性
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 はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
facebook/pyrefly のほかの issue
-
`errors` config docs don't make sense対応中かも @i098 が今日担当しました。 オープンdocumentation has-open-pr
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
-
. field visit support for typeddict対応中かも @MannXo が今日担当しました。 オープンgood first issue language-server
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
narrowing typechecking
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
-
Handle editable installs with .pth files対応中かも @connernilsen が 3 日前に担当しました。 オープンconfiguration
facebook/pyrefly の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
Cloud environment origin check accepts an explicit default HTTPS port (:443) (follow-up to #30418)オープンarea: cloud
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
manaflow-ai/cmux#31340 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
apache/datafusion#26999 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
quarto-dev/q2#1005 ·
メンテナーはふだん 1 日以内に返信
-
Chat stream: two tool calls with the same index but different ids are merged into one対応中かも @kunalgoesbyken が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
respanai/respan-gateway#136 ·
メンテナーはふだん 1 日以内に返信