matches_gitignore: directory-only patterns in nested .gitignore not excluded under --exclude-gitignore
還沒有人認領這個 Issue。
評估
研究方向
從 mypy/modulefinder.py 中的 matches_gitignore 開始,將其路徑處理與同層的 matches_exclude 進行比較。使用包含 sub/ 和一個實際子目錄的巢狀 .gitignore,執行所描述的 --exclude-gitignore 重現。完成標準是:僅匹配目錄的模式能夠排除 sub/ 及其下的檔案,並符合 git 的行為。
由索引模型根據 Issue 內容生成。
描述
Bug
matches_gitignore (mypy/modulefinder.py) fails to exclude a directory matched by a directory-only pattern (e.g. build/, node_modules/) when the pattern lives in a nested .gitignore (one in a scanned subdirectory), under --exclude-gitignore.
The trailing-slash decision uses the gitignore-relative path with a cwd-relative stat:
relative_path = os.path.relpath(subpath, gi_path)
if fscache.isdir(relative_path): # relative_path is relative to gi_path, but isdir resolves from cwd
relative_path = relative_path + "/"
When gi_path != cwd, relative_path doesn't resolve on disk, so isdir returns False, the / is never appended, and the directory-only pattern doesn't match — mypy then type-checks files the user intended to exclude.
The sibling matches_exclude in the same file does it correctly: it builds the match string with os.path.relpath(subpath) but calls fscache.isdir(subpath) on the original path.
To Reproduce
With --exclude-gitignore, a package dir containing a nested .gitignore whose content is sub/, where sub/ is a real subdirectory: mypy still checks files under sub/.
Expected Behavior
sub/ is excluded, matching git's own behavior for directory-only patterns.
Fix
Stat the original subpath (keep relative_path only for the spec match) — proposed in #21752.
- 主要語言
- Python
- 星號
- 20.6k
- 分支
- 3.3k
- 平均合併
- 1 天 9 小時
- 30 天內合併 PR
- 56
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
python/mypy 的其他 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 75/100
-
bug
難度 2/5 1-3 小時 新手友好度 76/100
-
documentation
難度 2/5 1-3 小時 新手友好度 72/100
-
bug topic-configuration topic-error-reporting
難度 2/5 1-3 小時 新手友好度 68/100
-
bug topic-attrs
難度 2/5 1-3 小時 新手友好度 62/100
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 88/100
-
難度 2/5 1-3 小時 新手友好度 82/100
-
難度 2/5 1-3 小時 新手友好度 78/100
-
enhancement
難度 2/5 1-3 小時 新手友好度 72/100
-
難度 2/5 1-3 小時 新手友好度 74/100